package com.ruoyi.service.impl;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.*;
import com.ruoyi.dto.EconomyDTO;
import com.ruoyi.dto.PartitionDTO;
import com.ruoyi.dto.UPSDTO;
import com.ruoyi.mapper.FinanceMapper;
import com.ruoyi.mapper.PartitionMapper;
import com.ruoyi.mapper.UPSMapper;
import com.ruoyi.service.FinanceService;
import lombok.var;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author:zzm
 * @Date: 2024/9/2 10:43
 */
@Service
public class FinanceServiceImpl implements FinanceService {

    @Autowired
    private PartitionMapper partitionMapper;
    @Autowired
    private UPSMapper upsMapper;
    @Autowired
    private FinanceMapper financeMapper;


    @Override
    public void twoToOne(HttpServletResponse response, MultipartFile operationsFile, MultipartFile detailsFile, boolean updateSupport) throws IOException {
        System.out.println("-------------------------------------------------------------------------------开始操作拉123-------------------------------------------------------------------------------");
        System.out.println(new Date());
        //导入物流费用明细表和库内操作表
        ExcelUtil<LibraryOperations> operationsUtil = new ExcelUtil<LibraryOperations>(LibraryOperations.class);
        ExcelUtil<LogisticsDetails> detailsUtil = new ExcelUtil<LogisticsDetails>(LogisticsDetails.class);
        List<LibraryOperations> operationsList = new ArrayList<>();
        List<LogisticsDetails> detailsList = new ArrayList<>();
        String sheetName = null;
        // 导入第一个Excel文件
        if (operationsFile.getOriginalFilename() != null) {
            operationsList = operationsUtil.importExcel(operationsFile.getInputStream());
            Workbook workbook = new XSSFWorkbook(operationsFile.getInputStream());
            sheetName = workbook.getSheetName(0);  // 获取第一个 Sheet 的名称
        }
        System.out.println("库内操作表导入完成");
        System.out.println(new Date());
        //将List的waybillNum字段提取作为Map的主键进行存储
        Map<String, List<LogisticsDetails>> waybillMap = new HashMap<>();
        if (detailsList != null) {
            for (LogisticsDetails details : detailsList) {
                String waybillNum = details.getWaybillNum();
                // 如果Map中没有这个waybillNum，就新建一个List
                waybillMap.computeIfAbsent(waybillNum, k -> new ArrayList<>());
                // 将waybill加入对应的List中
                waybillMap.get(waybillNum).add(details);
            }
        }
        System.out.println("Map提取完成");
        List<PartitionDTO> fadexList = partitionMapper.getList(null, null, null, null);
        List<UPSDTO> upsList = upsMapper.getList(null, null, null, null);
        //英尺换算--0.393700787402
        BigDecimal acre = new BigDecimal("0.393700787402");
        BigDecimal conversionFactor = new BigDecimal("0.0022046");
        // 使用并行流处理
        String finalSheetName = sheetName;
        operationsList.remove(0);
        for (LibraryOperations lo : operationsList) {
            // 构造错误信息
            List<List<String>> data = new ArrayList<>();
            if (!"是".equals(lo.getWaybill())) {
                if (lo.getPostalCode().length() < 5) {
                    data.add(Collections.singletonList("邮编长度错误,邮编为:" + lo.getPostalCode()));
                } else if (lo.getLength() == null || lo.getHeight() == null || lo.getWidth() == null || lo.getWeight() == null) {
                    data.add(Collections.singletonList("长宽高计费重错误,运单号为为::" + lo.getWaybillNum()));
                } else if (lo.getLogisticsProvider() == null || lo.getLogisticsMethod() == null) {
                    data.add(Collections.singletonList("物流商或物流方式错误,运单号为为::" + lo.getWaybillNum()));
                }
            }
            // 如果有错误信息，则立即导出并返回
            if (!data.isEmpty()) {
                // 设置响应头
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment; filename=error_info.xlsx");

                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    // 设置表头
                    List<List<String>> head = new ArrayList<>();
                    head.add(Collections.singletonList("错误"));

                    // 使用 EasyExcel 写入错误数据
                    EasyExcel.write(outputStream)
                            .head(head)
                            .sheet("错误信息")
                            .doWrite(data);

                    response.getOutputStream().write(outputStream.toByteArray());
                    response.getOutputStream().flush();
                }
                return; // 提前结束方法，只导出当前错误信息，其他不处理
            }
        }

        operationsList.parallelStream().forEach(item -> {
            if (!("wareHouse").equals(item.getWareHouse())) {
                if (finalSheetName.contains("渠道")) {
                    if (item.getUnit().contains("kg")) {
                        item.setUnit("cm/g");
                        item.setWeight(item.getWeight().multiply(new BigDecimal(1000)));
                    }
                }
                if (item.getUnit() != null) {
                    if (item.getUnit().contains("inch")) {
                        item.setLength(item.getLength().divide(acre, 2, RoundingMode.HALF_UP));
                        item.setHeight(item.getHeight().divide(acre, 2, RoundingMode.HALF_UP));
                        item.setWidth(item.getWidth().divide(acre, 2, RoundingMode.HALF_UP));
                        item.setWeight(item.getWeight().divide(conversionFactor, 2, RoundingMode.HALF_UP));
                        item.setUnit("cm/g");
                    } else if (item.getUnit().contains("kg") && item.getUnit().contains("cm")) {
                        item.setWeight(item.getWeight().multiply(new BigDecimal(1000)));
                        item.setUnit("cm/g");
                    }
                }
                //        -----------------------------匹配分区start-------------------------------
                if (item.getWareHouse() == "" || item.getWareHouse() == null) {
                    item.setPartition("错误");
                } else {
                    String wareHousePrefix = item.getWareHouse().substring(0, 2);
                    // 根据 logisticsProvider 决定使用哪个列表进行匹配
                    if ("FedEx".equalsIgnoreCase(item.getLogisticsProvider()) || "OMS".equalsIgnoreCase(item.getLogisticsProvider())) {
                        if (item.getPostalCode().replaceAll(" ", "").matches("[0-9-]+")) {
                            String postalCodePrefix = item.getPostalCode().trim().substring(0, 5);
                            for (PartitionDTO partition : fadexList) {
                                String partitionPrefix = partition.getWareHouse().substring(0, 2);
                                String[] postalCodeRange = partition.getDestinationZIP().split("-");
                                if (wareHousePrefix.equals(partitionPrefix)) {
                                    int startRange = Integer.parseInt(postalCodeRange[0].trim());
                                    int endRange = Integer.parseInt(postalCodeRange[1].trim());
                                    int postalCodeNumber = Integer.parseInt(postalCodePrefix);
                                    if (postalCodeNumber >= startRange && postalCodeNumber <= endRange) {
                                        item.setPartition(partition.getZone());
                                        break;
                                    }
                                }
                            }
                        } else {
                            item.setPartition("0");
                        }
                    } else if ("UPS".equalsIgnoreCase(item.getLogisticsProvider()) || "USPS".equalsIgnoreCase(item.getLogisticsProvider())) {
                        if (item.getPostalCode().replaceAll(" ", "").matches("[0-9-]+")) {
                            //如果是萨凡纳的根据fedex来进行分区
                            if ("sa".equals(item.getWareHouse().substring(0, 2))) {
                                String sa = item.getPostalCode().substring(0, 5);
                                for (PartitionDTO partition : fadexList) {
                                    String partitionPrefix = partition.getWareHouse().substring(0, 2);
                                    String[] postalCodeRange = partition.getDestinationZIP().split("-");
                                    if (wareHousePrefix.equals(partitionPrefix)) {
                                        int startRange = Integer.parseInt(postalCodeRange[0].trim());
                                        int endRange = Integer.parseInt(postalCodeRange[1].trim());
                                        int postalCodeNumber = Integer.parseInt(sa);
                                        if (postalCodeNumber >= startRange && postalCodeNumber <= endRange) {
                                            item.setPartition(partition.getZone());
                                            break;
                                        }
                                    }
                                }
                            } else {
                                String postalCodePrefix = item.getPostalCode().substring(0, 3);
                                for (UPSDTO ups : upsList) {
                                    String partitionPrefix = ups.getWareHouse().substring(0, 2);
                                    //先判断仓库名称是否相等
                                    if (wareHousePrefix.equals(partitionPrefix)) {
                                        if (ups.getDestinationZIP().equals(postalCodePrefix)) {
                                            item.setPartition(ups.getZone());
                                            break;
                                        }
                                    }
                                }
                            }
                        } else {
                            item.setPartition("0");
                        }

                    } else {
                        item.setPartition("0");
                    }
                }
                //        -----------------------------匹配分区end-------------------------------
                //        -----------------------------计费重start-------------------------------
                if (item.getLength() != null && item.getWidth() != null && item.getHeight() != null && item.getWeight() != null && !("").equals(item.getLength())) {
                    //实重(LB)
                    BigDecimal weight = new BigDecimal(String.valueOf(item.getWeight()));
                    //克转千克再*202046
                    BigDecimal actualWeight = weight.multiply(conversionFactor).setScale(2, RoundingMode.HALF_UP);
                    //长宽高转为英尺
                    BigDecimal length = new BigDecimal(String.valueOf(item.getLength()));
                    BigDecimal acreLength = length.multiply(acre).setScale(0, RoundingMode.UP);
                    BigDecimal width = new BigDecimal(String.valueOf(item.getWidth()));
                    BigDecimal acreWidth = width.multiply(acre).setScale(0, RoundingMode.UP);
                    BigDecimal height = new BigDecimal(String.valueOf(item.getHeight()));
                    BigDecimal acreHeight = height.multiply(acre).setScale(0, RoundingMode.UP);
                    //体积
                    BigDecimal volume = acreLength.multiply(acreWidth).multiply(acreHeight).setScale(2, RoundingMode.HALF_UP);
                    //围长
                    // 获取最大值
                    BigDecimal maxVal = acreLength.max(acreWidth).max(acreHeight);
                    //总长度
                    BigDecimal all = acreLength.add(acreWidth).add(acreHeight);
                    // 计算另外两个值的和
                    BigDecimal sumOfOtherTwo = all.subtract(maxVal);
                    // 计算最短边
                    BigDecimal minSide = acreLength.min(acreWidth).min(acreHeight);
                    // 计算第二长的边
                    BigDecimal secondMaxSide = all.subtract(maxVal).subtract(minSide);
                    // 最终结果：最大值 + 2 * (另外两个值相加)
                    BigDecimal wc = maxVal.add(sumOfOtherTwo.multiply(new BigDecimal("2")));
                    if ("FedEx".equalsIgnoreCase(item.getLogisticsProvider()) || "OMS".equalsIgnoreCase(item.getLogisticsProvider())) {
                        if (!"-".equals(item.getLogisticsMethod()) && item.getLogisticsMethod() != null && item.getLogisticsMethod() != "") {
                            if ("AN".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                    "EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                    "OS".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                    "MY".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                    "AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                    "AM".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                    "_C".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                    "_A".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                    "_B".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                                BigDecimal last = volume.divide(new BigDecimal("250"), 2, RoundingMode.HALF_UP);
                                item.setBillingWeight(actualWeight.compareTo(last) > 0 ? actualWeight : last);
                                //eco和ae渠道计费重逻辑增加：当SKU围长超84，计费重不足20lb按照20lb出
                                if ("MY".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                        "AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                                    if (wc.compareTo(new BigDecimal(84.00)) > 0 && item.getBillingWeight().compareTo(new BigDecimal(20)) < 0) {
                                        item.setBillingWeight(new BigDecimal(20.00));
                                    }
                                } else {
                                    //oversize
                                    //围长超130inch 计费重＜90lb，按照=90lb计算
                                    if (wc.compareTo(new BigDecimal("130")) >= 0 && item.getBillingWeight().compareTo(new BigDecimal("90")) < 0) {
                                        item.setBillingWeight(new BigDecimal("90.00"));
                                    }
                                    //超尺寸
                                    if ((maxVal.compareTo(new BigDecimal("48")) >= 0 && maxVal.compareTo(new BigDecimal("96")) <= 0)
                                            || (secondMaxSide.compareTo(new BigDecimal("30")) > 0) || (wc.compareTo(new BigDecimal("105")) > 0)) {
                                        if (item.getBillingWeight().compareTo(new BigDecimal(40)) < 0) {
                                            item.setBillingWeight(new BigDecimal("40"));
                                        }

                                    }
                                }
                            } else {
                                BigDecimal last = volume.divide(new BigDecimal("250"), 2, RoundingMode.HALF_UP);
                                item.setBillingWeight(actualWeight.compareTo(last) > 0 ? actualWeight : last);
                            }
                        } else {
                            item.setBillingWeight(new BigDecimal(0));
                        }
                    } else if (("UPS").equalsIgnoreCase(item.getLogisticsProvider()) || ("USPS").equalsIgnoreCase(item.getLogisticsProvider())) {
                        BigDecimal last = volume.divide(new BigDecimal("225"), 2, RoundingMode.HALF_UP);
                        item.setBillingWeight(actualWeight.compareTo(last) > 0 ? actualWeight : last);
                        //围长超130inch 计费重＜90lb，按照=90lb计算
                        if (wc.compareTo(new BigDecimal("130")) >= 0 && item.getBillingWeight().compareTo(new BigDecimal("90")) < 0) {
                            item.setBillingWeight(new BigDecimal("90.00"));
                        }
                    } else {
                        BigDecimal last = volume.divide(new BigDecimal("250"), 2, RoundingMode.HALF_UP);
                        item.setBillingWeight(actualWeight.compareTo(last) > 0 ? actualWeight : last);
                    }
                } else {
                    item.setPartition("0");
                    item.setBillingWeight(new BigDecimal(0));
                }
                //        -----------------------------计费重end--------------------------------

            }
        });


        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(LibraryOperations.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHead()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(operationsList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");

    }

    @Override
    public void costExport(HttpServletResponse response) throws Exception {
        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(LibraryOperationsCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHeadCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write((Collection<?>) null, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");
    }

    @Override
    public void cost(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws IOException {
        System.out.println(new Date());
        //导入库内操作表
        ExcelUtil<LibraryOperationsCost> costUtil = new ExcelUtil<LibraryOperationsCost>(LibraryOperationsCost.class);
        List<LibraryOperationsCost> costList = new ArrayList<>();
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null
            //&& costFile.getOriginalFilename().contains("库内")
        ) {
            costList = costUtil.importExcel(costFile.getInputStream());
        }
        //查询所有的成本费用
        //基础运费
        List<AMBasicRate> amBasicRateList = financeMapper.getBasicRate();
        List<AMBasicRate> economyList = financeMapper.getEconomyBasicRate();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = financeMapper.getEconomyCode();
        costList.remove(0);
        for (LibraryOperationsCost lo : costList) {
            // 构造错误信息
            List<List<String>> data = new ArrayList<>();
            if (lo.getPostalCode().length() < 5) {
                data.add(Collections.singletonList("邮编长度错误,邮编为:" + lo.getPostalCode()));
            } else if (lo.getLogisticsProvider() == null || lo.getLogisticsMethod() == null) {
                data.add(Collections.singletonList("物流商或物流方式错误,运单号为为::" + lo.getWaybillNum()));
            } else if (lo.getPartition() == null) {
                data.add(Collections.singletonList("分区错误,运单号为为::" + lo.getWaybillNum()));
            } else if (lo.getBillingWeight() == null) {
                data.add(Collections.singletonList("计费重错误,运单号为为::" + lo.getWaybillNum()));
            }
            // 如果有错误信息，则立即导出并返回
            if (!data.isEmpty()) {
                // 设置响应头
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment; filename=error_info.xlsx");

                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    // 设置表头
                    List<List<String>> head = new ArrayList<>();
                    head.add(Collections.singletonList("错误"));

                    // 使用 EasyExcel 写入错误数据
                    EasyExcel.write(outputStream)
                            .head(head)
                            .sheet("错误信息")
                            .doWrite(data);

                    response.getOutputStream().write(outputStream.toByteArray());
                    response.getOutputStream().flush();
                }
                return; // 提前结束方法，只导出当前错误信息，其他不处理
            }
        }
        // 使用并行流处理
        costList.parallelStream().forEach(item -> {
            //将费用明细变成0.00
            zeroCost(item);
            if (item.getPostalCode().trim().length() > 5 && !item.getPostalCode().contains("-")) {
                item.setColumn("错误");
            } else {
                if (!("wareHouse").equals(item.getWareHouse()) && !"是".equals(item.getWaybill()) && !"2".equals(item.getWaybill())
                        && item.getLogisticsProvider().contains("FedEx")) {
                    //AM的
                    if ("AM".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        int partition = Integer.parseInt(item.getPartition());
                        //基础运费成本
                        for (AMBasicRate rate : amBasicRateList) {
                            if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones().equals(item.getPartition())
                            ) {
                                item.setBasicRateCost(rate.getPrice());
                                item.setAmountCost(item.getAmountCost().add(rate.getPrice()));
                                break;
                            }
                        }
                        //操作附加费-超尺寸成本
                        if (item.getAHSDimensions().compareTo(BigDecimal.ZERO) > 0) {
                            if (partition == 2) {
                                item.setAHSDimensionsCost(new BigDecimal(4.20).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 3 || partition == 4) {
                                item.setAHSDimensionsCost(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 5 || partition == 6) {
                                item.setAHSDimensionsCost(new BigDecimal(5.10).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition >= 7) {
                                item.setAHSDimensionsCost(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                            }
                            item.setAmountCost(item.getAmountCost().add(item.getAHSDimensionsCost()));

                        }
                        //操作附加费-超重成本
                        if (item.getAHSWeight().compareTo(BigDecimal.ZERO) > 0) {
                            if (partition == 2) {
                                item.setAHSWeightCost(new BigDecimal(6.53).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 3 || partition == 4) {
                                item.setAHSWeightCost(new BigDecimal(7.13).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 5 || partition == 6) {
                                item.setAHSWeightCost(new BigDecimal(7.58).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition >= 7) {
                                item.setAHSWeightCost(new BigDecimal(8.25).setScale(2, RoundingMode.HALF_UP));
                            }
                            item.setAmountCost(item.getAmountCost().add(item.getAHSWeightCost()));
                        }
                        //旺季额外附加费
                        //超大超尺寸(区分-(Home Delivery)/(Ground))
                        if (item.getOversizeCharge().compareTo(BigDecimal.ZERO) > 0) {
                            if (item.getLogisticsMethod().contains("DELIVERY")) {
                                if (partition == 2) {
                                    item.setOversizeChargeCost(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setOversizeChargeCost(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setOversizeChargeCost(new BigDecimal(290.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setOversizeChargeCost(new BigDecimal(305.00).setScale(2, RoundingMode.HALF_UP));
                                }
                            } else if (item.getLogisticsMethod().contains("GROUND")) {
                                if (partition == 2) {
                                    item.setOversizeChargeCost(new BigDecimal(205.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setOversizeChargeCost(new BigDecimal(225.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setOversizeChargeCost(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setOversizeChargeCost(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                                }
                            }
                            item.setAmountCost(item.getAmountCost().add(item.getOversizeChargeCost()));
                        }
                        //旺季超大超尺寸附加费
                        //住宅附加费
                        if (item.getResidentialSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                            if (item.getLogisticsMethod().contains("DELIVERY")) {
                                item.setResidentialSurchargeCost(new BigDecimal(2.08).setScale(2, RoundingMode.HALF_UP));
                            } else if (item.getLogisticsMethod().contains("GROUND")) {
                                item.setResidentialSurchargeCost(new BigDecimal(5.95).setScale(2, RoundingMode.HALF_UP));
                            }
                            item.setAmountCost(item.getAmountCost().add(item.getResidentialSurchargeCost()));
                        }
                        //住宅旺季附加费
                        //包裹旺季附加费
                        //偏远地区附加费1
                        if (item.getDASResi().compareTo(BigDecimal.ZERO) > 0) {
                            item.setDASResiCost(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getDASResiCost()));
                        }
                        //偏远地区附加费2
                        if (item.getDASGround().compareTo(BigDecimal.ZERO) > 0) {
                            item.setDASGround(new BigDecimal(1.68).setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getDASGroundCost()));
                        }
                        //超偏远地区附加费1
                        if (item.getDASEXTENDEDHomeDelivery().compareTo(BigDecimal.ZERO) > 0) {
                            item.setDASEXTENDEDHomeDeliveryCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getDASEXTENDEDHomeDeliveryCost()));
                        }
                        //超偏远地区附加费2
                        if (item.getDASEXTENDEDGround().compareTo(BigDecimal.ZERO) > 0) {
                            item.setDASEXTENDEDGroundCost(new BigDecimal(2.10).setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getDASEXTENDEDGroundCost()));
                        }
                        //超级偏远地区附加费1
                        if (item.getDASRemoteComm().compareTo(BigDecimal.ZERO) > 0) {
                            item.setDASRemoteCommCost(new BigDecimal(6.20).setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getDASRemoteCommCost()));
                        }
                        //超级偏远地区附加费2
                        if (item.getDASRemoteResi().compareTo(BigDecimal.ZERO) > 0) {
                            item.setDASRemoteResiCost(new BigDecimal(6.20).setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getDASRemoteResiCost()));
                        }
                        //签名服务费
                        if (item.getIndirectSignatureRequired().compareTo(BigDecimal.ZERO) > 0) {
                            item.setIndirectSignatureRequiredCost(new BigDecimal(3.58).setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getIndirectSignatureRequiredCost()));
                        }
                        //燃油附加费(所有费用成本*16.25%*50%)
                        if (item.getFuelSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                            item.setFuelSurchargeCost(item.getAmountCost().multiply(new BigDecimal("0.5").multiply(new BigDecimal("0.1625")))
                                    .setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getFuelSurchargeCost()));
                        }
                        //销售利润率
                        item.setSalesProfit(item.getTotalCost()
                                .subtract(item.getAmountCost()) // 计算 (售价-成本)
                                .divide(item.getAmountCost(), 4, RoundingMode.HALF_UP));


                    } else if ("MY".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        //基础运费成本
                        //AEO渠道计费重超过71LB,上线寄出运费按照71LB
                        if ("MY".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                "AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                            for (AMBasicRate rate : economyList) {
                                if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                        && rate.getZones().equals(item.getPartition())
                                ) {
                                    item.setBasicRateCost(rate.getPrice());
                                    item.setAmountCost(item.getAmountCost().add(rate.getPrice()));
                                    break;
                                }
                            }
                        } else if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                            if (item.getBillingWeight().setScale(0, RoundingMode.CEILING).compareTo(new BigDecimal(71.00)) > 0) {
                                for (AMBasicRate rate : economyList) {
                                    if (rate.getWeight().equals(new BigDecimal(71.00))
                                            && rate.getZones().equals(item.getPartition())
                                    ) {
                                        item.setBasicRateCost(rate.getPrice());
                                        item.setAmountCost(item.getAmountCost().add(rate.getPrice()));
                                        break;
                                    }
                                }
                            } else {
                                for (AMBasicRate rate : economyList) {
                                    if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                            && rate.getZones().equals(item.getPartition())
                                    ) {
                                        item.setBasicRateCost(rate.getPrice());
                                        item.setAmountCost(item.getAmountCost().add(rate.getPrice()));
                                        break;
                                    }
                                }
                            }

                        }

                        //偏远地区
                        for (EconomyDTO dto : economyCodeList) {
                            if (dto.getCode().equals(item.getPostalCode().substring(0, 5))) {
                                if ("偏远".equals(dto.getType())) {
                                    item.setDAS(new BigDecimal(1.52).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmountCost(item.getAmountCost().add(item.getDAS()));
                                    break;
                                } else if ("超偏远".equals(dto.getType())) {
                                    item.setDASExtended(new BigDecimal(2.02).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmountCost(item.getAmountCost().add(item.getDASExtended()));
                                    break;
                                }

                            }
                        }
                        //燃油附加费(所有费用成本*16.25%*70%)
                        if (item.getFuelSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                            item.setFuelSurchargeCost(item.getAmountCost().multiply(new BigDecimal("0.7").multiply(new BigDecimal("0.1625")))
                                    .setScale(2, RoundingMode.HALF_UP));
                            item.setAmountCost(item.getAmountCost().add(item.getFuelSurchargeCost()));
                        }
                        //销售利润率
                        item.setSalesProfit(item.getTotalCost()
                                .subtract(item.getAmountCost()) // 计算 (售价-成本)
                                .divide(item.getAmountCost(), 4, RoundingMode.HALF_UP));


                    }

                }
            }
        });
        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(LibraryOperationsCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHeadCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");


    }

    @Override
    //之前的长宽高的
    public void oldSurroundCost(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------之前的长宽高-----------------------------");
        System.out.println(new Date());
        System.out.println(new Date());
        //导入库内操作表
        ExcelUtil<SurroundCost> costUtil = new ExcelUtil<SurroundCost>(SurroundCost.class);
        List<SurroundCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("AM") || costFile.getOriginalFilename().contains("am")) {
                type = "AM";
            }
        }
        //实重(LB)
        BigDecimal conversionFactor = new BigDecimal("0.0022046");
        //英尺换算--0.393700787402
        BigDecimal acre = new BigDecimal("0.393700787402");
        //查询所有的成本费用
        List<AMBasicRate> amBasicRateList = financeMapper.getBasicRate();
        List<AMBasicRate> economyList = financeMapper.getEconomyBasicRate();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = financeMapper.getEconomyCode();
        // 使用并行流处理
        String finalType = type;
        for (SurroundCost lo : costList) {
            // 构造错误信息
            List<List<String>> data = new ArrayList<>();
            if (lo.getRecipientZipCode().length() < 5) {
                data.add(Collections.singletonList("邮编长度错误,邮编为:" + lo.getRecipientZipCode()));
            } else if (lo.getLength() == null || lo.getHeight() == null || lo.getWidth() == null || lo.getWeight() == null) {
                data.add(Collections.singletonList("长宽高计费重错误"));
            } else if (lo.getZoneCode() == null) {
                data.add(Collections.singletonList("分区错误,分区为::" + lo.getZoneCode()));
            } else if (lo.getBillingWeight() == null) {
                data.add(Collections.singletonList("计费重错误,计费重为::" + lo.getBillingWeight()));
            }
            // 如果有错误信息，则立即导出并返回
            if (!data.isEmpty()) {
                // 设置响应头
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment; filename=error_info.xlsx");

                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    // 设置表头
                    List<List<String>> head = new ArrayList<>();
                    head.add(Collections.singletonList("错误"));

                    // 使用 EasyExcel 写入错误数据
                    EasyExcel.write(outputStream)
                            .head(head)
                            .sheet("错误信息")
                            .doWrite(data);

                    response.getOutputStream().write(outputStream.toByteArray());
                    response.getOutputStream().flush();
                }
                return; // 提前结束方法，只导出当前错误信息，其他不处理
            }
        }
        costList.parallelStream().forEach(item -> {
            zeroSurroundCost(item);
            Integer partition = Integer.valueOf(item.getZoneCode());
            //克转千克再*202046
            BigDecimal actualWeight = item.getWeight().multiply(conversionFactor).setScale(2, RoundingMode.HALF_UP);
            //长宽高转为英尺
            BigDecimal acreLength = item.getLength().multiply(acre).setScale(0, RoundingMode.UP);
            BigDecimal acreWidth = item.getWidth().multiply(acre).setScale(0, RoundingMode.UP);
            BigDecimal acreHeight = item.getHeight().multiply(acre).setScale(0, RoundingMode.UP);
            //体积
            BigDecimal volume = acreLength.multiply(acreWidth).multiply(acreHeight).setScale(2, RoundingMode.HALF_UP);
            //围长
            // perimeter=max(length,width,height)+(length+width+height−max(length,width,height))×2
            // 计算最长边
            BigDecimal maxSide = acreLength.max(acreWidth).max(acreHeight);
            // 计算最短边
            BigDecimal minSide = acreLength.min(acreWidth).min(acreHeight);
            //总长度
            BigDecimal all = acreLength.add(acreWidth).add(acreHeight);
            // 计算第二长的边
            BigDecimal secondMaxSide = all.subtract(maxSide).subtract(minSide);
            // 计算另外两个值的和
            BigDecimal sumOfOtherTwo = all.subtract(maxSide);
            // 最终结果：最大值 + 2 * (另外两个值相加)
            BigDecimal perimeter = maxSide.add(sumOfOtherTwo.multiply(new BigDecimal(2)));
            item.setInches(perimeter);
            BigDecimal last = volume.divide(new BigDecimal(250), 2, RoundingMode.HALF_UP);
            item.setBillingWeight(actualWeight.compareTo(last) > 0 ? actualWeight : last);
            if (item.getBillingWeight().compareTo(new BigDecimal("71")) >= 0 && !("AM").equals(finalType)) {
                item.setBillingWeight(new BigDecimal("71"));
            }
            //是否偏远
            for (EconomyDTO dto : economyCodeList) {
                if (dto.getCode().equals(item.getRecipientZipCode().substring(0, 5))) {
                    if ("偏远".equals(dto.getType())) {
                        item.setDASResi(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("偏远");
                        break;
                    } else if ("超偏远".equals(dto.getType())) {
                        item.setDASExtendedResi(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("超偏远");
                        break;
                    } else if ("超级偏远".equals(dto.getType())) {
                        item.setDASRemoteComm(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("超超偏远");
                        break;
                    }
                }
            }
            //是否为AHS或OVERSIZE
            if ((perimeter.compareTo(new BigDecimal("130")) >= 0 && perimeter.compareTo(new BigDecimal("165")) < 0) ||
                    (maxSide.compareTo(new BigDecimal("96")) >= 0 && maxSide.compareTo(new BigDecimal("108")) < 0)) {
                item.setIsAHSOrOverSize("OverSize");
                if ("AM".equals(finalType)) {
                    item.setBillingWeight(new BigDecimal(90));
                }
            } else if (item.getWeight().multiply(new BigDecimal(0.0022046)).compareTo(new BigDecimal("50")) > 0 &&
                    item.getWeight().multiply(new BigDecimal(0.0022046)).compareTo(new BigDecimal("150")) <= 0) {
                item.setIsAHSOrOverSize("AHS(超重)");
            } else if ((perimeter.compareTo(new BigDecimal("105")) > 0 && perimeter.compareTo(new BigDecimal("129")) <= 0) ||
                    (secondMaxSide.compareTo(new BigDecimal("30")) >= 0) ||
                    (maxSide.compareTo(new BigDecimal("48")) >= 0 && maxSide.compareTo(new BigDecimal("96")) < 0)) {
                item.setIsAHSOrOverSize("AHS(超尺寸)");
            }
            if ("AM".equals(finalType)) {
                //基础运费成本
                if (item.getBillingWeight().compareTo(BigDecimal.valueOf(150)) <= 0) {
                    for (AMBasicRate rate : amBasicRateList) {
                        if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                && rate.getZones() == Integer.parseInt(item.getZoneCode())) {
                            item.setBaseRate(rate.getPrice());
                            item.setAmount(item.getAmount().add(rate.getPrice()));
                            break;
                        }
                    }
                }
                //超大超尺寸
                if (item.getIsAHSOrOverSize().contains("OverSize")) {
                    if (partition == 2) {
                        item.setOversizeCharge(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setOversizeCharge(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setOversizeCharge(new BigDecimal(290.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setOversizeCharge(new BigDecimal(305.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getOversizeCharge()));
                }
                //操作附加费-超尺寸成本
                if (item.getIsAHSOrOverSize().contains("超尺寸")) {
                    if (partition == 2) {
                        item.setAHSDimensions(new BigDecimal(4.20).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setAHSDimensions(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setAHSDimensions(new BigDecimal(5.10).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setAHSDimensions(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getAHSDimensions()));
                }
                //操作附加费-超重成本
                if (item.getIsAHSOrOverSize().contains("超重")) {
                    if (partition == 2) {
                        item.setAHSWeight(new BigDecimal(6.53).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setAHSWeight(new BigDecimal(7.13).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setAHSWeight(new BigDecimal(7.58).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setAHSWeight(new BigDecimal(8.25).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getAHSWeight()));
                }
                //住宅附加费
                item.setResidential(new BigDecimal(2.08).setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getResidential()));
                //偏远
                if ("偏远".equals(item.getIsRemote())) {
                    item.setDASResi(new BigDecimal(2.48));
                    item.setAmount(item.getAmount().add(item.getDASResi()));
                }
                //超偏远
                if ("超偏远".equals(item.getIsRemote())) {
                    item.setDASExtendedResi(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASExtendedResi()));
                }
                //超级偏远
                if ("超级偏远".equals(item.getIsRemote())) {
                    item.setDASRemoteComm(new BigDecimal(6.20));
                    item.setAmount(item.getAmount().add(item.getDASRemoteComm()));
                }
                //燃油附加费(所有费用成本*16.25%*50%)
                item.setFuelSurcharge(item.getAmount().multiply(new BigDecimal("0.5").multiply(new BigDecimal("0.18")))
                        .setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getFuelSurcharge()));
            } else {
                //基础运费成本
                for (AMBasicRate rate : economyList) {
                    if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                            && rate.getZones() == Integer.parseInt(item.getZoneCode())) {
                        item.setBaseRate(rate.getPrice());
                        item.setAmount(item.getAmount().add(item.getBaseRate()));
                        break;
                    }
                }
                //偏远
                if ("偏远".equals(item.getIsRemote())) {
                    item.setDASResi(new BigDecimal(2.48));
                    item.setAmount(item.getAmount().add(item.getDASResi()));
                }
                //超偏远
                if ("超偏远".equals(item.getIsRemote())) {
                    item.setDASExtendedResi(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASExtendedResi()));
                }
                //超级偏远
                if ("超级偏远".equals(item.getIsRemote())) {
                    item.setDASRemoteComm(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASRemoteComm()));
                }
                //燃油附加费(所有费用成本*16.25%*70%)
                item.setFuelSurcharge(item.getAmount().multiply(new BigDecimal("0.7").multiply(new BigDecimal("0.18")))
                        .setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getFuelSurcharge()));
            }


        });


        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(SurroundCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHeadSurroundCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");
    }


    @Override
    //之前的超长的
    public void oldLongCost(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------超长的成本开始了-----------------------------");
        System.out.println(new Date());
        System.out.println(new Date());
        //导入库内操作表
        ExcelUtil<LongCost> costUtil = new ExcelUtil<LongCost>(LongCost.class);
        List<LongCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("AM") || costFile.getOriginalFilename().contains("am")) {
                type = "AM";
            }
        }
        //查询所有的成本费用
        List<AMBasicRate> amBasicRateList = financeMapper.getBasicRate();
        List<AMBasicRate> economyList = financeMapper.getEconomyBasicRate();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = financeMapper.getEconomyCode();
        System.out.println("____________________" + type + "____________________________________________");
        // 使用并行流处理
        if (("AM").equals(type)) {
            costList.parallelStream().forEach(item -> {
                zeroLongCost(item);
                int partition = 0;
                if (item.getZoneCode().matches("\\d+")) {
                    partition = Integer.parseInt(item.getZoneCode());
                }
                //基础运费成本
                if (item.getRatedWeightAmount() != null) {
                    if (item.getRatedWeightAmount().compareTo(BigDecimal.valueOf(150)) <= 0) {
                        for (AMBasicRate rate : amBasicRateList) {
                            if (rate.getWeight().equals(item.getRatedWeightAmount())
                                    && rate.getZones() == partition) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                    }
                }
                //旺季的 等到次年2月再用
//                //旺季额外附加费
//                if (item.getDemandAddlHandling() != null) {
//                    if (item.getDemandAddlHandling().compareTo(BigDecimal.ZERO) > 0) {
//                        item.setDemandAddlHandlingCost(new BigDecimal(4.00));
//                        item.setAmount(item.getAmount().add(item.getDemandAddlHandlingCost()));
//                    }
//                }
//                //旺季超大超尺寸附加费
//                if (item.getDemandOversize() != null) {
//                    if (item.getDemandOversize().compareTo(BigDecimal.ZERO) > 0) {
//                        item.setDemandOversizeCost(new BigDecimal(43.52));
//                        item.setAmount(item.getAmount().add(item.getDemandOversizeCost()));
//                    }
//                }
//                //包裹旺季附加费
//                if (item.getDemandSurcharge() != null) {
//                    if (item.getDemandSurcharge().compareTo(BigDecimal.ZERO) > 0) {
//                        item.setDemandSurchargeCost(new BigDecimal(0.15));
//                        item.setAmount(item.getAmount().add(item.getDemandSurchargeCost()));
//                    }
//                }

                //超大超尺寸(区分-(Home Delivery)/(Ground))
                if (item.getOversizeCharge() != null) {
                    if (item.getOversizeCharge().compareTo(BigDecimal.ZERO) > 0) {
                        if (item.getLogisticsMethod().contains("DELIVERY")) {
                            if (partition == 2) {
                                item.setOversizeChargeCost(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 3 || partition == 4) {
                                item.setOversizeChargeCost(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 5 || partition == 6) {
                                item.setOversizeChargeCost(new BigDecimal(290.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition >= 7) {
                                item.setOversizeChargeCost(new BigDecimal(305.00).setScale(2, RoundingMode.HALF_UP));
                            }
                        } else if (item.getLogisticsMethod().contains("GROUND")) {
                            if (partition == 2) {
                                item.setOversizeChargeCost(new BigDecimal(205.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 3 || partition == 4) {
                                item.setOversizeChargeCost(new BigDecimal(225.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 5 || partition == 6) {
                                item.setOversizeChargeCost(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition >= 7) {
                                item.setOversizeChargeCost(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                            }
                        }
                        item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                    }
                }
                //操作附加费-超尺寸成本
                if (item.getAHSDimensions() != null) {
                    if (item.getAHSDimensions().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAHSDimensionsCost(new BigDecimal(4.20).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAHSDimensionsCost(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAHSDimensionsCost(new BigDecimal(5.10).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAHSDimensionsCost(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()));
                    }
                }
                //操作附加费-超重成本
                if (item.getAHSWeight() != null) {
                    if (item.getAHSWeight().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAHSWeightCost(new BigDecimal(6.53).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAHSWeightCost(new BigDecimal(7.13).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAHSWeightCost(new BigDecimal(7.58).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAHSWeightCost(new BigDecimal(8.25).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                    }
                }
                //操作附加费-超包装
                if (item.getAdditionalHandling() != null) {
                    if (item.getAdditionalHandling().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAdditionalHandlingCost(new BigDecimal(25.00).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAdditionalHandlingCost(new BigDecimal(29.00).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAdditionalHandlingCost(new BigDecimal(30.50).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAdditionalHandlingCost(new BigDecimal(31.50).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAdditionalHandlingCost()));
                    }
                }
                //住宅附加费
                if (item.getResidential() != null) {
                    if (item.getResidential().compareTo(BigDecimal.ZERO) > 0) {
                        if (item.getLogisticsMethod().contains("DELIVERY")) {
                            item.setResidentialCost(new BigDecimal(2.08).setScale(2, RoundingMode.HALF_UP));
                        } else if (item.getLogisticsMethod().contains("GROUND")) {
                            item.setResidentialCost(new BigDecimal(5.95).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getResidentialCost()));
                    }
                }
                //偏远地区附加费1
                if (item.getDASResi() != null) {
                    if (item.getDASResi().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASResiCost(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                        item.setText("偏远");
                        item.setAmount(item.getAmount().add(item.getDASResiCost()));
                    }
                }
                //偏远地区附加费2
                if (item.getDASComm() != null) {
                    if (item.getDASComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASCommCost(new BigDecimal(1.68).setScale(2, RoundingMode.HALF_UP));
                        item.setText("偏远");
                        item.setAmount(item.getAmount().add(item.getDASCommCost()));
                    }
                }

                //超偏远地区附加费1
                if (item.getDASExtendedResi() != null) {
                    if (item.getDASExtendedResi().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASExtendedResiCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超偏远");
                        item.setAmount(item.getAmount().add(item.getDASExtendedResiCost()));
                    }
                }
                //超偏远地区附加费2
                if (item.getDASExtendedComm() != null) {
                    if (item.getDASExtendedComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASExtendedCommCost(new BigDecimal(2.10).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超偏远");
                        item.setAmount(item.getAmount().add(item.getDASExtendedCommCost()));
                    }
                }
                //超级偏远地区附加费3
                if (item.getDASRemoteResidential() != null) {
                    if (item.getDASRemoteResidential().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASRemoteResidentialCost(new BigDecimal(6.20).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超级偏远");
                        item.setAmount(item.getAmount().add(item.getDASRemoteResidential()));
                    }
                }
                //超级偏远地区附加费1
                if (item.getDASRemoteComm() != null) {
                    if (item.getDASRemoteComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASRemoteCommCost(new BigDecimal(6.208).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超级偏远");
                        item.setAmount(item.getAmount().add(item.getDASRemoteCommCost()));
                    }
                }
                //地址更正费
                if (item.getAddressCorrection() != null) {
                    if (item.getAddressCorrection().compareTo(BigDecimal.ZERO) > 0) {
                        item.setAddressCorrectionCost(new BigDecimal(9.60).setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getAddressCorrectionCost()));
                    }
                }
                //燃油附加费(所有费用成本*16.25%*75%)
                if (item.getFuelSurcharge() != null) {
                    if (item.getFuelSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                        item.setFuelSurchargeCost(item.getFuelSurcharge().divide(item.getNetChargeAmount().subtract(item.getFuelSurcharge()), 4, RoundingMode.HALF_UP)
                                .multiply(item.getAmount()).setScale(2, RoundingMode.HALF_UP));

//                        item.setFuelSurchargeCost(item.getAmount().multiply(new BigDecimal("0.75").multiply(new BigDecimal("0.1625")))
//                                .setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                    }
                }
                //差异
                item.setDifference(item.getNetChargeAmount().subtract(item.getAmount()));
            });
        } else {
            costList.parallelStream().forEach(item -> {
                zeroLongCost(item);
                int partition = 0;
                if (item.getZoneCode().matches("\\d+")) {
                    partition = Integer.parseInt(item.getZoneCode());
                }
                if (item.getLogisticsMethod().length() > 2) {
                    //基础运费成本
                    //AEO渠道计费重超过71LB,上线寄出运费按照71LB(取消)
                    if ("MY".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        for (AMBasicRate rate : economyList) {
                            if (item.getRatedWeightAmount() != null) {
                                if (rate.getWeight().equals(item.getRatedWeightAmount().setScale(0, RoundingMode.CEILING))
                                        && rate.getZones() == partition
                                ) {
                                    item.setBaseRateCost(rate.getPrice());
                                    item.setAmount(item.getAmount().add(rate.getPrice()));
                                    break;
                                }
                            }
                        }
                    } else if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
//                    if (item.getRatedWeightAmount().setScale(0, RoundingMode.CEILING).compareTo(new BigDecimal(71.00)) > 0) {
//                        for (AMBasicRate rate : economyList) {
//                            if (rate.getWeight().equals(new BigDecimal(71.00))
//                                    && rate.getZones()==partition
//                            ) {
//                                item.setBaseRateCost(rate.getPrice());
//                                item.setAmount(item.getAmount().add(rate.getPrice()));
//                                break;
//                            }
//                        }
//                    } else {
                        for (AMBasicRate rate : economyList) {
                            if (rate.getWeight().equals(item.getRatedWeightAmount().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones() == partition
                            ) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                        //}

                    }
                    //偏远地区
                    for (EconomyDTO dto : economyCodeList) {
                        if (item.getRecipientZipCode().length() >= 5) {
                            if (dto.getCode().equals(item.getRecipientZipCode().substring(0, 5))) {
                                if ("偏远".equals(dto.getType())) {
                                    item.setDASResiCost(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASResiCost()));
                                    item.setText("偏远");
                                    break;
                                } else if ("超偏远".equals(dto.getType())) {
                                    item.setDASExtendedResiCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASExtendedResiCost()));
                                    item.setText("超偏远");
                                    break;
                                } else if ("超级偏远".equals(dto.getType())) {
                                    item.setDASRemoteResidentialCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASRemoteResidentialCost()));
                                    item.setText("超超偏远");
                                    break;
                                }
                            }
                        }
                    }
                    //燃油附加费
                    item.setFuelSurchargeCost(item.getFuelSurcharge().divide(item.getNetChargeAmount().subtract(item.getFuelSurcharge()), 4, RoundingMode.HALF_UP)
                            .multiply(item.getAmount()).setScale(2, RoundingMode.HALF_UP));
                    item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                    //差异
                    item.setDifference(item.getNetChargeAmount().subtract(item.getAmount()));
                }
            });

        }

        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(LongCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHeadLongCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");

    }

    @Override
    public void longCost(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------超长的成本开始了-----------------------------");
        //导入库内操作表
        ExcelUtil<LongCost> costUtil = new ExcelUtil<LongCost>(LongCost.class);
        List<LongCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("AM") || costFile.getOriginalFilename().contains("am")) {
                type = "AM";
            }
        }
        //查询所有的成本费用
        //AM分home和ground
        List<AMBasicRate> amBasicRateListHome = financeMapper.getBasicRateHome();
        List<AMBasicRate> amBasicRateListGround = financeMapper.getBasicRateGround();
        List<AMBasicRate> economyList = financeMapper.getEconomyBasicRate();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = financeMapper.getEconomyCode();
        System.out.println("____________________" + type + "____________________________________________");
        // 使用并行流处理
        if (("AM").equals(type)) {
            costList.parallelStream().forEach(item -> {
                zeroLongCost(item);
                int partition = 0;
                if (item.getZoneCode().matches("\\d+")) {
                    partition = Integer.parseInt(item.getZoneCode());
                }
                //基础运费成本
                if (item.getRatedWeightAmount() != null) {
                    if (item.getRatedWeightAmount().compareTo(BigDecimal.valueOf(150)) <= 0) {
                        if (item.getLogisticsMethod().contains("HOME")) {
                            for (AMBasicRate rate : amBasicRateListHome) {
                                if (rate.getWeight().equals(item.getRatedWeightAmount())
                                        && rate.getZones() == partition) {
                                    item.setBaseRateCost(rate.getPrice());
                                    item.setAmount(item.getAmount().add(rate.getPrice()));
                                    break;
                                }
                            }
                        } else {
                            for (AMBasicRate rate : amBasicRateListGround) {
                                if (rate.getWeight().equals(item.getRatedWeightAmount())
                                        && rate.getZones() == partition) {
                                    item.setBaseRateCost(rate.getPrice());
                                    item.setAmount(item.getAmount().add(rate.getPrice()));
                                    break;
                                }
                            }
                        }
                    }
                }
                //旺季的 等到次年2月再用
//                //旺季额外附加费
//                if (item.getDemandAddlHandling() != null) {
//                    if (item.getDemandAddlHandling().compareTo(BigDecimal.ZERO) > 0) {
//                        item.setDemandAddlHandlingCost(new BigDecimal(4.00));
//                        item.setAmount(item.getAmount().add(item.getDemandAddlHandlingCost()));
//                    }
//                }
//                //旺季超大超尺寸附加费
//                if (item.getDemandOversize() != null) {
//                    if (item.getDemandOversize().compareTo(BigDecimal.ZERO) > 0) {
//                        item.setDemandOversizeCost(new BigDecimal(43.52));
//                        item.setAmount(item.getAmount().add(item.getDemandOversizeCost()));
//                    }
//                }
//                //包裹旺季附加费
//                if (item.getDemandSurcharge() != null) {
//                    if (item.getDemandSurcharge().compareTo(BigDecimal.ZERO) > 0) {
//                        item.setDemandSurchargeCost(new BigDecimal(0.15));
//                        item.setAmount(item.getAmount().add(item.getDemandSurchargeCost()));
//                    }
//                }

                //超大超尺寸(区分-(Home Delivery)/(Ground))
                if (item.getOversizeCharge() != null) {
                    if (item.getOversizeCharge().compareTo(BigDecimal.ZERO) > 0) {
                        if (item.getLogisticsMethod().contains("DELIVERY")) {
                            if (partition == 2) {
                                item.setOversizeChargeCost(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 3 || partition == 4) {
                                item.setOversizeChargeCost(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 5 || partition == 6) {
                                item.setOversizeChargeCost(new BigDecimal(297.50).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition >= 7) {
                                item.setOversizeChargeCost(new BigDecimal(305.00).setScale(2, RoundingMode.HALF_UP));
                            }
                        } else if (item.getLogisticsMethod().contains("GROUND")) {
                            if (partition == 2) {
                                item.setOversizeChargeCost(new BigDecimal(205.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 3 || partition == 4) {
                                item.setOversizeChargeCost(new BigDecimal(225.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 5 || partition == 6) {
                                item.setOversizeChargeCost(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition >= 7) {
                                item.setOversizeChargeCost(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                            }
                        }
                        item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                    }
                }
                //操作附加费-超尺寸成本
                if (item.getAHSDimensions() != null) {
                    if (item.getAHSDimensions().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAHSDimensionsCost(new BigDecimal(4.20).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAHSDimensionsCost(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAHSDimensionsCost(new BigDecimal(5.40).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAHSDimensionsCost(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()));
                    }
                }
                //操作附加费-超重成本
                if (item.getAHSWeight() != null) {
                    if (item.getAHSWeight().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAHSWeightCost(new BigDecimal(6.53).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAHSWeightCost(new BigDecimal(7.13).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAHSWeightCost(new BigDecimal(7.91).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAHSWeightCost(new BigDecimal(8.25).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                    }
                }
                //操作附加费-超包装
                if (item.getAdditionalHandling() != null) {
                    if (item.getAdditionalHandling().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAdditionalHandlingCost(new BigDecimal(3.75).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAdditionalHandlingCost(new BigDecimal(4.35).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAdditionalHandlingCost(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAdditionalHandlingCost(new BigDecimal(4.73).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAdditionalHandlingCost()));
                    }
                }
                //住宅附加费
                if (item.getResidential() != null) {
                    if (item.getResidential().compareTo(BigDecimal.ZERO) > 0) {
                        if (item.getLogisticsMethod().contains("DELIVERY")) {
                            item.setResidentialCost(new BigDecimal(2.08).setScale(2, RoundingMode.HALF_UP));
                        } else if (item.getLogisticsMethod().contains("GROUND")) {
                            item.setResidentialCost(new BigDecimal(5.95).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getResidentialCost()));
                    }
                }
                //偏远地区附加费1
                if (item.getDASResi() != null) {
                    if (item.getDASResi().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASResiCost(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                        item.setText("偏远");
                        item.setAmount(item.getAmount().add(item.getDASResiCost()));
                    }
                }
                //偏远地区附加费2
                if (item.getDASComm() != null) {
                    if (item.getDASComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASCommCost(new BigDecimal(1.68).setScale(2, RoundingMode.HALF_UP));
                        item.setText("偏远");
                        item.setAmount(item.getAmount().add(item.getDASCommCost()));
                    }
                }

                //超偏远地区附加费1
                if (item.getDASExtendedResi() != null) {
                    if (item.getDASExtendedResi().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASExtendedResiCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超偏远");
                        item.setAmount(item.getAmount().add(item.getDASExtendedResiCost()));
                    }
                }
                //超偏远地区附加费2
                if (item.getDASExtendedComm() != null) {
                    if (item.getDASExtendedComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASExtendedCommCost(new BigDecimal(2.10).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超偏远");
                        item.setAmount(item.getAmount().add(item.getDASExtendedCommCost()));
                    }
                }
                //超级偏远地区附加费3
                if (item.getDASRemoteResidential() != null) {
                    if (item.getDASRemoteResidential().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASRemoteResidentialCost(new BigDecimal(6.20).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超级偏远");
                        item.setAmount(item.getAmount().add(item.getDASRemoteResidential()));
                    }
                }
                //超级偏远地区附加费1
                if (item.getDASRemoteComm() != null) {
                    if (item.getDASRemoteComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASRemoteCommCost(new BigDecimal(6.20).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超级偏远");
                        item.setAmount(item.getAmount().add(item.getDASRemoteCommCost()));
                    }
                }
                //地址更正费
                if (item.getAddressCorrection() != null) {
                    if (item.getAddressCorrection().compareTo(BigDecimal.ZERO) > 0) {
                        item.setAddressCorrectionCost(new BigDecimal(9.60).setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getAddressCorrectionCost()));
                    }
                }
                //燃油附加费(所有费用成本*16.25%*75%)
                if (item.getFuelSurcharge() != null) {
                    if (item.getFuelSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                        item.setFuelSurchargeCost(item.getFuelSurcharge().divide(item.getNetChargeAmount().subtract(item.getFuelSurcharge()), 4, RoundingMode.HALF_UP)
                                .multiply(item.getAmount()).setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                    }
                }
                //差异
                item.setDifference(item.getNetChargeAmount().subtract(item.getAmount()));
            });
        } else {
            costList.parallelStream().forEach(item -> {
                zeroLongCost(item);
                int partition = 0;
                if (item.getZoneCode().matches("\\d+")) {
                    partition = Integer.parseInt(item.getZoneCode());
                }
                if (item.getLogisticsMethod().length() > 2) {
                    //基础运费成本
                    //AEO渠道计费重超过71LB,上线寄出运费按照71LB(取消)
                    if ("MY".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        for (AMBasicRate rate : economyList) {
                            if (item.getRatedWeightAmount() != null) {
                                if (rate.getWeight().equals(item.getRatedWeightAmount().setScale(0, RoundingMode.CEILING))
                                        && rate.getZones() == partition
                                ) {
                                    item.setBaseRateCost(rate.getPrice());
                                    item.setAmount(item.getAmount().add(rate.getPrice()));
                                    break;
                                }
                            }
                        }
                    } else if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "OS".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        for (AMBasicRate rate : economyList) {
                            if (rate.getWeight().equals(item.getRatedWeightAmount().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones() == partition
                            ) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                        //}

                    }
                    //偏远地区
                    for (EconomyDTO dto : economyCodeList) {
                        if (item.getRecipientZipCode().length() >= 5) {
                            if (dto.getCode().equals(item.getRecipientZipCode().substring(0, 5))) {
                                if ("偏远".equals(dto.getType())) {
                                    item.setDASResiCost(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASResiCost()));
                                    item.setText("偏远");
                                    break;
                                } else if ("超偏远".equals(dto.getType())) {
                                    item.setDASExtendedResiCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASExtendedResiCost()));
                                    item.setText("超偏远");
                                    break;
                                } else if ("超级偏远".equals(dto.getType())) {
                                    item.setDASRemoteResidentialCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASRemoteResidentialCost()));
                                    item.setText("超超偏远");
                                    break;
                                }
                            }
                        }
                    }
                    //燃油附加费
                    item.setFuelSurchargeCost(item.getFuelSurcharge().divide(item.getNetChargeAmount().subtract(item.getFuelSurcharge()), 4, RoundingMode.HALF_UP)
                            .multiply(item.getAmount()).setScale(2, RoundingMode.HALF_UP));
                    item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                    //差异
                    item.setDifference(item.getNetChargeAmount().subtract(item.getAmount()));
                }
            });

        }

        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(LongCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHeadLongCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");

    }

    @Override
    public void longCostBusy(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------超长的成本-旺季-----------------------------");
        //导入库内操作表
        ExcelUtil<LongCost> costUtil = new ExcelUtil<LongCost>(LongCost.class);
        List<LongCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("AM") || costFile.getOriginalFilename().contains("am")) {
                type = "AM";
            }
        }
        //查询所有的成本费用
        //AM分home和ground
        List<AMBasicRate> amBasicRateListHome = financeMapper.getBasicRateHome();
        List<AMBasicRate> amBasicRateListGround = financeMapper.getBasicRateGround();
        List<AMBasicRate> economyList = financeMapper.getEconomyBasicRate();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = financeMapper.getEconomyCode();
        System.out.println("____________________" + type + "____________________________________________");
        // 使用并行流处理
        if (("AM").equals(type)) {
            costList.parallelStream().forEach(item -> {
                zeroLongCost(item);
                int partition = 0;
                if (item.getZoneCode().matches("\\d+")) {
                    partition = Integer.parseInt(item.getZoneCode());
                }
                //基础运费成本
                if (item.getRatedWeightAmount() != null) {
                    if (item.getRatedWeightAmount().compareTo(BigDecimal.valueOf(150)) <= 0) {
                        if (item.getLogisticsMethod().contains("HOME")) {
                            for (AMBasicRate rate : amBasicRateListHome) {
                                if (rate.getWeight().equals(item.getRatedWeightAmount())
                                        && rate.getZones() == partition) {
                                    item.setBaseRateCost(rate.getPrice());
                                    item.setAmount(item.getAmount().add(rate.getPrice()));
                                    break;
                                }
                            }
                        } else {
                            for (AMBasicRate rate : amBasicRateListGround) {
                                if (rate.getWeight().equals(item.getRatedWeightAmount())
                                        && rate.getZones() == partition) {
                                    item.setBaseRateCost(rate.getPrice());
                                    item.setAmount(item.getAmount().add(rate.getPrice()));
                                    break;
                                }
                            }
                        }
                    }
                }
                //旺季的 等到次年2月再用
                //旺季额外附加费
//                if (item.getDemandAddlHandling() != null) {
//                    if (item.getDemandAddlHandling().compareTo(BigDecimal.ZERO) > 0) {
//                        item.setDemandAddlHandlingCost(new BigDecimal(4.00));
//                        item.setAmount(item.getAmount().add(item.getDemandAddlHandlingCost()));
//                    }
//                }
                //旺季超大超尺寸附加费
                if (item.getDemandOversize() != null) {
                    if (item.getDemandOversize().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDemandOversizeCost(new BigDecimal(45.00));
                        item.setAmount(item.getAmount().add(item.getDemandOversizeCost()));
                    }
                }
                //包裹旺季附加费
                if (item.getDemandSurcharge() != null) {
                    if (item.getDemandSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDemandSurchargeCost(new BigDecimal(0.4));
                        item.setAmount(item.getAmount().add(item.getDemandSurchargeCost()));
                    }
                }

                //超大超尺寸(区分-(Home Delivery)/(Ground))
                if (item.getOversizeCharge() != null) {
                    if (item.getOversizeCharge().compareTo(BigDecimal.ZERO) > 0) {
                        if (item.getLogisticsMethod().contains("DELIVERY")) {
                            if (partition == 2) {
                                item.setOversizeChargeCost(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 3 || partition == 4) {
                                item.setOversizeChargeCost(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 5 || partition == 6) {
                                item.setOversizeChargeCost(new BigDecimal(297.50).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition >= 7) {
                                item.setOversizeChargeCost(new BigDecimal(305.00).setScale(2, RoundingMode.HALF_UP));
                            }
                        } else if (item.getLogisticsMethod().contains("GROUND")) {
                            if (partition == 2) {
                                item.setOversizeChargeCost(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 3 || partition == 4) {
                                item.setOversizeChargeCost(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition == 5 || partition == 6) {
                                item.setOversizeChargeCost(new BigDecimal(297.50).setScale(2, RoundingMode.HALF_UP));
                            }
                            if (partition >= 7) {
                                item.setOversizeChargeCost(new BigDecimal(305.00).setScale(2, RoundingMode.HALF_UP));
                            }
                        }
                        item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                    }
                }
                //操作附加费-超尺寸成本
                if (item.getAHSDimensions() != null) {
                    if (item.getAHSDimensions().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAHSDimensionsCost(new BigDecimal(4.20).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAHSDimensionsCost(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAHSDimensionsCost(new BigDecimal(5.40).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAHSDimensionsCost(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()));
                    }
                }
                //操作附加费-超重成本
                if (item.getAHSWeight() != null) {
                    if (item.getAHSWeight().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAHSWeightCost(new BigDecimal(6.53).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAHSWeightCost(new BigDecimal(7.13).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAHSWeightCost(new BigDecimal(7.91).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAHSWeightCost(new BigDecimal(8.25).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                    }
                }
                //操作附加费-超包装
                if (item.getAdditionalHandling() != null) {
                    if (item.getAdditionalHandling().compareTo(BigDecimal.ZERO) > 0) {
                        if (partition == 2) {
                            item.setAdditionalHandlingCost(new BigDecimal(3.75).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 3 || partition == 4) {
                            item.setAdditionalHandlingCost(new BigDecimal(4.35).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition == 5 || partition == 6) {
                            item.setAdditionalHandlingCost(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                        }
                        if (partition >= 7) {
                            item.setAdditionalHandlingCost(new BigDecimal(4.73).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getAdditionalHandlingCost()));
                    }
                }
                //ahs旺季附加费 看尺寸超重包装任意有一个就有
                if (item.getAHSDimensions() != null || item.getAHSWeight() != null || item.getAdditionalHandling() != null) {
                    if (item.getAHSDimensions().compareTo(BigDecimal.ZERO) > 0 || item.getAHSWeight().compareTo(BigDecimal.ZERO) > 0
                            || item.getAdditionalHandling().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDemandAddlHandlingCost(new BigDecimal(4.13).setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getDemandAddlHandlingCost()));
                    }
                }
                //住宅附加费
                if (item.getResidential() != null) {
                    if (item.getResidential().compareTo(BigDecimal.ZERO) > 0) {
                        if (item.getLogisticsMethod().contains("DELIVERY")) {
                            item.setResidentialCost(new BigDecimal(2.08).setScale(2, RoundingMode.HALF_UP));
                            item.setDemandResidentialCost(new BigDecimal(1.10).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getDemandResidentialCost()));
                        } else if (item.getLogisticsMethod().contains("GROUND")) {
                            item.setResidentialCost(new BigDecimal(5.95).setScale(2, RoundingMode.HALF_UP));
                        }
                        item.setAmount(item.getAmount().add(item.getResidentialCost()));
                    }
                }
                //偏远地区附加费1
                if (item.getDASResi() != null) {
                    if (item.getDASResi().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASResiCost(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                        item.setText("偏远");
                        item.setAmount(item.getAmount().add(item.getDASResiCost()));
                    }
                }
                //偏远地区附加费2
                if (item.getDASComm() != null) {
                    if (item.getDASComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASCommCost(new BigDecimal(1.68).setScale(2, RoundingMode.HALF_UP));
                        item.setText("偏远");
                        item.setAmount(item.getAmount().add(item.getDASCommCost()));
                    }
                }

                //超偏远地区附加费1
                if (item.getDASExtendedResi() != null) {
                    if (item.getDASExtendedResi().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASExtendedResiCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超偏远");
                        item.setAmount(item.getAmount().add(item.getDASExtendedResiCost()));
                    }
                }
                //超偏远地区附加费2
                if (item.getDASExtendedComm() != null) {
                    if (item.getDASExtendedComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASExtendedCommCost(new BigDecimal(2.10).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超偏远");
                        item.setAmount(item.getAmount().add(item.getDASExtendedCommCost()));
                    }
                }
                //超级偏远地区附加费3
                if (item.getDASRemoteResidential() != null) {
                    if (item.getDASRemoteResidential().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASRemoteResidentialCost(new BigDecimal(6.20).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超级偏远");
                        item.setAmount(item.getAmount().add(item.getDASRemoteResidential()));
                    }
                }
                //超级偏远地区附加费1
                if (item.getDASRemoteComm() != null) {
                    if (item.getDASRemoteComm().compareTo(BigDecimal.ZERO) > 0) {
                        item.setDASRemoteCommCost(new BigDecimal(6.20).setScale(2, RoundingMode.HALF_UP));
                        item.setText("超级偏远");
                        item.setAmount(item.getAmount().add(item.getDASRemoteCommCost()));
                    }
                }
                //地址更正费
                if (item.getAddressCorrection() != null) {
                    if (item.getAddressCorrection().compareTo(BigDecimal.ZERO) > 0) {
                        item.setAddressCorrectionCost(new BigDecimal(9.60).setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getAddressCorrectionCost()));
                    }
                }
                //燃油附加费(所有费用成本*16.25%*75%)
                if (item.getFuelSurcharge() != null) {
                    if (item.getFuelSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                        item.setFuelSurchargeCost(item.getFuelSurcharge().divide(item.getNetChargeAmount().subtract(item.getFuelSurcharge()), 4, RoundingMode.HALF_UP)
                                .multiply(item.getAmount()).setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                    }
                }
                //差异
                item.setDifference(item.getNetChargeAmount().subtract(item.getAmount()));
            });
        } else {
            costList.parallelStream().forEach(item -> {
                zeroLongCost(item);
                int partition = 0;
                if (item.getZoneCode().matches("\\d+")) {
                    partition = Integer.parseInt(item.getZoneCode());
                }
                if (item.getLogisticsMethod().length() > 2) {
                    //基础运费成本
                    //AEO渠道计费重超过71LB,上线寄出运费按照71LB(取消)
                    if ("MY".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        for (AMBasicRate rate : economyList) {
                            if (item.getRatedWeightAmount() != null) {
                                if (rate.getWeight().equals(item.getRatedWeightAmount().setScale(0, RoundingMode.CEILING))
                                        && rate.getZones() == partition
                                ) {
                                    item.setBaseRateCost(rate.getPrice());
                                    item.setAmount(item.getAmount().add(rate.getPrice()));
                                    break;
                                }
                            }
                        }
                    } else if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "OS".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        for (AMBasicRate rate : economyList) {
                            if (rate.getWeight().equals(item.getRatedWeightAmount().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones() == partition
                            ) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                        //}

                    }
                    //偏远地区
                    for (EconomyDTO dto : economyCodeList) {
                        if (item.getRecipientZipCode().length() >= 5) {
                            if (dto.getCode().equals(item.getRecipientZipCode().substring(0, 5))) {
                                if ("偏远".equals(dto.getType())) {
                                    item.setDASResiCost(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASResiCost()));
                                    item.setText("偏远");
                                    break;
                                } else if ("超偏远".equals(dto.getType())) {
                                    item.setDASExtendedResiCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASExtendedResiCost()));
                                    item.setText("超偏远");
                                    break;
                                } else if ("超级偏远".equals(dto.getType())) {
                                    item.setDASRemoteResidentialCost(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDASRemoteResidentialCost()));
                                    item.setText("超超偏远");
                                    break;
                                }
                            }
                        }
                    }
                    //燃油附加费
                    item.setFuelSurchargeCost(item.getFuelSurcharge().divide(item.getNetChargeAmount().subtract(item.getFuelSurcharge()), 4, RoundingMode.HALF_UP)
                            .multiply(item.getAmount()).setScale(2, RoundingMode.HALF_UP));
                    item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                    //差异
                    item.setDifference(item.getNetChargeAmount().subtract(item.getAmount()));
                }
            });

        }

        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(LongCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHeadLongCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");

    }

    @Override
    public void handleExport(HttpServletResponse response) {
        ExcelUtil<SurroundCost> util = new ExcelUtil<SurroundCost>(SurroundCost.class);
        util.exportExcel(response, null, "成本模板");
    }

    @Override
    public void surroundCost(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------长宽高成本开始了-----------------------------");
        System.out.println(new Date());
        System.out.println(new Date());
        //导入库内操作表
        ExcelUtil<SurroundCost> costUtil = new ExcelUtil<SurroundCost>(SurroundCost.class);
        List<SurroundCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("AM") || costFile.getOriginalFilename().contains("am")) {
                type = "AM";
            }
        }
        //实重(LB)
        BigDecimal conversionFactor = new BigDecimal("0.0022046");
        //英尺换算--0.393700787402
        BigDecimal acre = new BigDecimal("0.393700787402");
        //查询所有的成本费用
        //AM分home和ground
        List<AMBasicRate> amBasicRateListHome = financeMapper.getBasicRateHome();
        List<AMBasicRate> economyList = financeMapper.getEconomyBasicRate();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = financeMapper.getEconomyCode();
        // 使用并行流处理
        String finalType = type;
        for (SurroundCost lo : costList) {
            // 构造错误信息
            List<List<String>> data = new ArrayList<>();
            if (lo.getRecipientZipCode().length() < 5) {
                data.add(Collections.singletonList("邮编长度错误,邮编为:" + lo.getRecipientZipCode()));
            } else if (lo.getLength() == null || lo.getHeight() == null || lo.getWidth() == null || lo.getWeight() == null) {
                data.add(Collections.singletonList("长宽高计费重错误"));
            } else if (lo.getZoneCode() == null) {
                data.add(Collections.singletonList("分区错误,分区为::" + lo.getZoneCode()));
            } else if (lo.getBillingWeight() == null) {
                data.add(Collections.singletonList("计费重错误,计费重为::" + lo.getBillingWeight()));
            }
            // 如果有错误信息，则立即导出并返回
            if (!data.isEmpty()) {
                // 设置响应头
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment; filename=error_info.xlsx");

                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    // 设置表头
                    List<List<String>> head = new ArrayList<>();
                    head.add(Collections.singletonList("错误"));

                    // 使用 EasyExcel 写入错误数据
                    EasyExcel.write(outputStream)
                            .head(head)
                            .sheet("错误信息")
                            .doWrite(data);

                    response.getOutputStream().write(outputStream.toByteArray());
                    response.getOutputStream().flush();
                }
                return; // 提前结束方法，只导出当前错误信息，其他不处理
            }
        }
        costList.parallelStream().forEach(item -> {
            zeroSurroundCost(item);
            Integer partition = Integer.valueOf(item.getZoneCode());
            //克转千克再*202046
            BigDecimal actualWeight = item.getWeight().multiply(conversionFactor).setScale(2, RoundingMode.HALF_UP);
            //长宽高转为英尺
            BigDecimal acreLength = item.getLength().multiply(acre).setScale(0, RoundingMode.UP);
            BigDecimal acreWidth = item.getWidth().multiply(acre).setScale(0, RoundingMode.UP);
            BigDecimal acreHeight = item.getHeight().multiply(acre).setScale(0, RoundingMode.UP);
            //体积
            BigDecimal volume = acreLength.multiply(acreWidth).multiply(acreHeight).setScale(2, RoundingMode.HALF_UP);
            //围长
            // perimeter=max(length,width,height)+(length+width+height−max(length,width,height))×2
            // 计算最长边
            BigDecimal maxSide = acreLength.max(acreWidth).max(acreHeight);
            // 计算最短边
            BigDecimal minSide = acreLength.min(acreWidth).min(acreHeight);
            //总长度
            BigDecimal all = acreLength.add(acreWidth).add(acreHeight);
            // 计算第二长的边
            BigDecimal secondMaxSide = all.subtract(maxSide).subtract(minSide);
            // 计算另外两个值的和
            BigDecimal sumOfOtherTwo = all.subtract(maxSide);
            // 最终结果：最大值 + 2 * (另外两个值相加)
            BigDecimal perimeter = maxSide.add(sumOfOtherTwo.multiply(new BigDecimal(2)));
            item.setInches(perimeter);
            BigDecimal last = volume.divide(new BigDecimal(250), 2, RoundingMode.HALF_UP);
            item.setBillingWeight(actualWeight.compareTo(last) > 0 ? actualWeight : last);
            if (item.getBillingWeight().compareTo(new BigDecimal("71")) >= 0 && !("AM").equals(finalType)) {
                item.setBillingWeight(new BigDecimal("71"));
            }

            //是否偏远
            for (EconomyDTO dto : economyCodeList) {
                if (dto.getCode().equals(item.getRecipientZipCode().substring(0, 5))) {
                    if ("偏远".equals(dto.getType())) {
                        item.setDASResi(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("偏远");
                        break;
                    } else if ("超偏远".equals(dto.getType())) {
                        item.setDASExtendedResi(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("超偏远");
                        break;
                    } else if ("超级偏远".equals(dto.getType())) {
                        item.setDASRemoteComm(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("超超偏远");
                        break;
                    }
                }
            }
            //是否为AHS或OVERSIZE
            if ((perimeter.compareTo(new BigDecimal("130")) >= 0 && perimeter.compareTo(new BigDecimal("165")) < 0) ||
                    (maxSide.compareTo(new BigDecimal("96")) >= 0 && maxSide.compareTo(new BigDecimal("108")) < 0)) {
                item.setIsAHSOrOverSize("OverSize");
                if ("AM".equals(finalType)) {
                    item.setBillingWeight(new BigDecimal(90));
                }

            } else if (item.getWeight().multiply(new BigDecimal(0.0022046)).compareTo(new BigDecimal("50")) > 0 &&
                    item.getWeight().multiply(new BigDecimal(0.0022046)).compareTo(new BigDecimal("150")) <= 0) {
                item.setIsAHSOrOverSize("AHS(超重)");
            } else if ((perimeter.compareTo(new BigDecimal("105")) > 0 && perimeter.compareTo(new BigDecimal("129")) <= 0) ||
                    (secondMaxSide.compareTo(new BigDecimal("30")) >= 0) ||
                    (maxSide.compareTo(new BigDecimal("48")) >= 0 && maxSide.compareTo(new BigDecimal("96")) < 0)) {
                item.setIsAHSOrOverSize("AHS(超尺寸)");
            }
            if ("AM".equals(finalType)) {
                //基础运费成本
                if (item.getBillingWeight().compareTo(BigDecimal.valueOf(150)) <= 0) {
                    for (AMBasicRate rate : amBasicRateListHome) {
                        if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                && rate.getZones() == Integer.parseInt(item.getZoneCode())) {
                            item.setBaseRate(rate.getPrice());
                            item.setAmount(item.getAmount().add(rate.getPrice()));
                            break;
                        }
                    }
                }
                //超大超尺寸
                if (item.getIsAHSOrOverSize().contains("OverSize")) {
                    if (partition == 2) {
                        item.setOversizeCharge(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setOversizeCharge(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setOversizeCharge(new BigDecimal(297.50).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setOversizeCharge(new BigDecimal(305.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getOversizeCharge()));
                }
                //操作附加费-超尺寸成本
                if (item.getIsAHSOrOverSize().contains("超尺寸")) {
                    if (partition == 2) {
                        item.setAHSDimensions(new BigDecimal(4.20).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setAHSDimensions(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setAHSDimensions(new BigDecimal(5.40).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setAHSDimensions(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getAHSDimensions()));
                }
                //操作附加费-超重成本
                if (item.getIsAHSOrOverSize().contains("超重")) {
                    if (partition == 2) {
                        item.setAHSWeight(new BigDecimal(6.53).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setAHSWeight(new BigDecimal(7.13).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setAHSWeight(new BigDecimal(7.91).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setAHSWeight(new BigDecimal(8.25).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getAHSWeight()));
                }
                //住宅附加费
                item.setResidential(new BigDecimal(2.08).setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getResidential()));
                //偏远
                if ("偏远".equals(item.getIsRemote())) {
                    item.setDASResi(new BigDecimal(2.48));
                    item.setAmount(item.getAmount().add(item.getDASResi()));
                }
                //超偏远
                if ("超偏远".equals(item.getIsRemote())) {
                    item.setDASExtendedResi(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASExtendedResi()));
                }
                //超级偏远
                if ("超级偏远".equals(item.getIsRemote())) {
                    item.setDASRemoteComm(new BigDecimal(6.20));
                    item.setAmount(item.getAmount().add(item.getDASRemoteComm()));
                }
                //燃油附加费(所有费用成本*16.25%*50%)
                item.setFuelSurcharge(item.getAmount().multiply(new BigDecimal("0.5").multiply(new BigDecimal("0.18")))
                        .setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getFuelSurcharge()));
            } else {
                //基础运费成本
                for (AMBasicRate rate : economyList) {
                    if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                            && rate.getZones() == Integer.parseInt(item.getZoneCode())) {
                        item.setBaseRate(rate.getPrice());
                        item.setAmount(item.getAmount().add(item.getBaseRate()));
                        break;
                    }
                }
                //偏远
                if ("偏远".equals(item.getIsRemote())) {
                    item.setDASResi(new BigDecimal(2.48));
                    item.setAmount(item.getAmount().add(item.getDASResi()));
                }
                //超偏远
                if ("超偏远".equals(item.getIsRemote())) {
                    item.setDASExtendedResi(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASExtendedResi()));
                }
                //超级偏远
                if ("超级偏远".equals(item.getIsRemote())) {
                    item.setDASRemoteComm(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASRemoteComm()));
                }
                //燃油附加费(所有费用成本*16.25%*70%)
                item.setFuelSurcharge(item.getAmount().multiply(new BigDecimal("0.7").multiply(new BigDecimal("0.18")))
                        .setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getFuelSurcharge()));
            }


        });


        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(SurroundCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHeadSurroundCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");
    }

    @Override
    public void surroundCostBusy(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------长宽高成本-旺季-----------------------------");
        //导入库内操作表
        ExcelUtil<SurroundCost> costUtil = new ExcelUtil<SurroundCost>(SurroundCost.class);
        List<SurroundCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("AM") || costFile.getOriginalFilename().contains("am")) {
                type = "AM";
            }
        }
        //实重(LB)
        BigDecimal conversionFactor = new BigDecimal("0.0022046");
        //英尺换算--0.393700787402
        BigDecimal acre = new BigDecimal("0.393700787402");
        //查询所有的成本费用
        //AM分home和ground
        List<AMBasicRate> amBasicRateListHome = financeMapper.getBasicRateHome();
        List<AMBasicRate> economyList = financeMapper.getEconomyBasicRate();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = financeMapper.getEconomyCode();
        // 使用并行流处理
        String finalType = type;
        for (SurroundCost lo : costList) {
            // 构造错误信息
            List<List<String>> data = new ArrayList<>();
            if (lo.getRecipientZipCode().length() < 5) {
                data.add(Collections.singletonList("邮编长度错误,邮编为:" + lo.getRecipientZipCode()));
            } else if (lo.getLength() == null || lo.getHeight() == null || lo.getWidth() == null || lo.getWeight() == null) {
                data.add(Collections.singletonList("长宽高计费重错误"));
            } else if (lo.getZoneCode() == null) {
                data.add(Collections.singletonList("分区错误,分区为::" + lo.getZoneCode()));
            } else if (lo.getBillingWeight() == null) {
                data.add(Collections.singletonList("计费重错误,计费重为::" + lo.getBillingWeight()));
            }
            // 如果有错误信息，则立即导出并返回
            if (!data.isEmpty()) {
                // 设置响应头
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment; filename=error_info.xlsx");

                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    // 设置表头
                    List<List<String>> head = new ArrayList<>();
                    head.add(Collections.singletonList("错误"));

                    // 使用 EasyExcel 写入错误数据
                    EasyExcel.write(outputStream)
                            .head(head)
                            .sheet("错误信息")
                            .doWrite(data);

                    response.getOutputStream().write(outputStream.toByteArray());
                    response.getOutputStream().flush();
                }
                return; // 提前结束方法，只导出当前错误信息，其他不处理
            }
        }
        costList.parallelStream().forEach(item -> {
            zeroSurroundCost(item);
            Integer partition = Integer.valueOf(item.getZoneCode());
            //克转千克再*202046
            BigDecimal actualWeight = item.getWeight().multiply(conversionFactor).setScale(2, RoundingMode.HALF_UP);
            //长宽高转为英尺
            BigDecimal acreLength = item.getLength().multiply(acre).setScale(0, RoundingMode.UP);
            BigDecimal acreWidth = item.getWidth().multiply(acre).setScale(0, RoundingMode.UP);
            BigDecimal acreHeight = item.getHeight().multiply(acre).setScale(0, RoundingMode.UP);
            //体积
            BigDecimal volume = acreLength.multiply(acreWidth).multiply(acreHeight).setScale(2, RoundingMode.HALF_UP);
            //围长
            // perimeter=max(length,width,height)+(length+width+height−max(length,width,height))×2
            // 计算最长边
            BigDecimal maxSide = acreLength.max(acreWidth).max(acreHeight);
            // 计算最短边
            BigDecimal minSide = acreLength.min(acreWidth).min(acreHeight);
            //总长度
            BigDecimal all = acreLength.add(acreWidth).add(acreHeight);
            // 计算第二长的边
            BigDecimal secondMaxSide = all.subtract(maxSide).subtract(minSide);
            // 计算另外两个值的和
            BigDecimal sumOfOtherTwo = all.subtract(maxSide);
            // 最终结果：最大值 + 2 * (另外两个值相加)
            BigDecimal perimeter = maxSide.add(sumOfOtherTwo.multiply(new BigDecimal(2)));
            item.setInches(perimeter);
            BigDecimal last = volume.divide(new BigDecimal(250), 2, RoundingMode.HALF_UP);
            item.setBillingWeight(actualWeight.compareTo(last) > 0 ? actualWeight : last);
            if (item.getBillingWeight().compareTo(new BigDecimal("71")) >= 0 && !("AM").equals(finalType)) {
                item.setBillingWeight(new BigDecimal("71"));
            }
            //是否偏远
            for (EconomyDTO dto : economyCodeList) {
                if (dto.getCode().equals(item.getRecipientZipCode().substring(0, 5))) {
                    if ("偏远".equals(dto.getType())) {
                        item.setDASResi(new BigDecimal(2.48).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("偏远");
                        break;
                    } else if ("超偏远".equals(dto.getType())) {
                        item.setDASExtendedResi(new BigDecimal(3.32).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("超偏远");
                        break;
                    } else if ("超级偏远".equals(dto.getType())) {
                        item.setDASRemoteComm(new BigDecimal(6.20).setScale(2, RoundingMode.HALF_UP));
                        item.setIsRemote("超超偏远");
                        break;
                    }
                }
            }
            //是否为AHS或OVERSIZE
            if ((perimeter.compareTo(new BigDecimal("130")) >= 0 && perimeter.compareTo(new BigDecimal("165")) < 0) ||
                    (maxSide.compareTo(new BigDecimal("96")) >= 0 && maxSide.compareTo(new BigDecimal("108")) < 0)) {
                item.setIsAHSOrOverSize("OverSize");
                if ("AM".equals(finalType)) {
                    item.setBillingWeight(new BigDecimal(90));
                }
            } else if (item.getWeight().multiply(new BigDecimal(0.0022046)).compareTo(new BigDecimal("50")) > 0 &&
                    item.getWeight().multiply(new BigDecimal(0.0022046)).compareTo(new BigDecimal("150")) <= 0) {
                item.setIsAHSOrOverSize("AHS(超重)");

            } else if ((perimeter.compareTo(new BigDecimal("105")) > 0 && perimeter.compareTo(new BigDecimal("129")) <= 0) ||
                    (secondMaxSide.compareTo(new BigDecimal("30")) >= 0) ||
                    (maxSide.compareTo(new BigDecimal("48")) >= 0 && maxSide.compareTo(new BigDecimal("96")) < 0)) {
                item.setIsAHSOrOverSize("AHS(超尺寸)");
            }
            if ("AM".equals(finalType)) {
                //包裹旺季附加费
                item.setDemandSurcharge(new BigDecimal(0.4).setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getDemandSurcharge()));
                //基础运费成本
                if (item.getBillingWeight().compareTo(BigDecimal.valueOf(150)) <= 0) {
                    for (AMBasicRate rate : amBasicRateListHome) {
                        if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                && rate.getZones() == Integer.parseInt(item.getZoneCode())) {
                            item.setBaseRate(rate.getPrice());
                            item.setAmount(item.getAmount().add(rate.getPrice()));
                            break;
                        }
                    }
                }
                //超大超尺寸
                if (item.getIsAHSOrOverSize().contains("OverSize")) {
                    if (partition == 2) {
                        item.setOversizeCharge(new BigDecimal(240.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setOversizeCharge(new BigDecimal(260.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setOversizeCharge(new BigDecimal(297.50).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setOversizeCharge(new BigDecimal(305.00).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getOversizeCharge()));
                    //旺季超大超尺寸附加费
                    item.setDemandOversize(new BigDecimal(45.00));
                    item.setAmount(item.getAmount().add(item.getDemandOversize()));
                }
                //操作附加费-超尺寸成本
                if (item.getIsAHSOrOverSize().contains("超尺寸")) {
                    if (partition == 2) {
                        item.setAHSDimensions(new BigDecimal(4.20).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setAHSDimensions(new BigDecimal(4.65).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setAHSDimensions(new BigDecimal(5.40).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setAHSDimensions(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getAHSDimensions()));
                    //旺季ahs
                    item.setDemandAddlHandling(new BigDecimal(4.13).setScale(2, RoundingMode.HALF_UP));
                    item.setAmount(item.getAmount().add(item.getDemandAddlHandling()));
                }
                //操作附加费-超重成本
                if (item.getIsAHSOrOverSize().contains("超重")) {
                    if (partition == 2) {
                        item.setAHSWeight(new BigDecimal(6.53).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 3 || partition == 4) {
                        item.setAHSWeight(new BigDecimal(7.13).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition == 5 || partition == 6) {
                        item.setAHSWeight(new BigDecimal(7.91).setScale(2, RoundingMode.HALF_UP));
                    }
                    if (partition >= 7) {
                        item.setAHSWeight(new BigDecimal(8.25).setScale(2, RoundingMode.HALF_UP));
                    }
                    item.setAmount(item.getAmount().add(item.getAHSWeight()));
                    //旺季ahs
                    item.setDemandAddlHandling(new BigDecimal(4.13).setScale(2, RoundingMode.HALF_UP));
                    item.setAmount(item.getAmount().add(item.getDemandAddlHandling()));
                }
                //住宅附加费
                item.setResidential(new BigDecimal(2.08).setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getResidential()));
                //住宅附加费-旺季
                item.setResidentialBusy(new BigDecimal(1.10).setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getResidentialBusy()));
                //偏远
                if ("偏远".equals(item.getIsRemote())) {
                    item.setDASResi(new BigDecimal(2.48));
                    item.setAmount(item.getAmount().add(item.getDASResi()));
                }
                //超偏远
                if ("超偏远".equals(item.getIsRemote())) {
                    item.setDASExtendedResi(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASExtendedResi()));
                }
                //超级偏远
                if ("超级偏远".equals(item.getIsRemote())) {
                    item.setDASRemoteComm(new BigDecimal(6.20));
                    item.setAmount(item.getAmount().add(item.getDASRemoteComm()));
                }
                //燃油附加费(所有费用成本*16.25%*50%)
                item.setFuelSurcharge(item.getAmount().multiply(new BigDecimal("0.5").multiply(new BigDecimal("0.18")))
                        .setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getFuelSurcharge()));
            } else {
                //基础运费成本
                for (AMBasicRate rate : economyList) {
                    if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                            && rate.getZones() == Integer.parseInt(item.getZoneCode())) {
                        item.setBaseRate(rate.getPrice());
                        item.setAmount(item.getAmount().add(item.getBaseRate()));
                        break;
                    }
                }
                //偏远
                if ("偏远".equals(item.getIsRemote())) {
                    item.setDASResi(new BigDecimal(2.48));
                    item.setAmount(item.getAmount().add(item.getDASResi()));
                }
                //超偏远
                if ("超偏远".equals(item.getIsRemote())) {
                    item.setDASExtendedResi(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASExtendedResi()));
                }
                //超级偏远
                if ("超级偏远".equals(item.getIsRemote())) {
                    item.setDASRemoteComm(new BigDecimal(3.32));
                    item.setAmount(item.getAmount().add(item.getDASRemoteComm()));
                }
                //燃油附加费(所有费用成本*16.25%*70%)
                item.setFuelSurcharge(item.getAmount().multiply(new BigDecimal("0.7").multiply(new BigDecimal("0.18")))
                        .setScale(2, RoundingMode.HALF_UP));
                item.setAmount(item.getAmount().add(item.getFuelSurcharge()));
            }


        });


        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(SurroundCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHeadSurroundCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");
    }


    @Override
    public void partitionWeightExport(HttpServletResponse response) throws Exception {
        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(LibraryOperations.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getHead()).build();
            // 将所有数据写入这个工作表
            excelWriter.write((Collection<?>) null, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");
    }


    @Override
    public void draggingCabinet(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws IOException {
        System.out.println("---------------------------------拖柜成本核算开始-----------------------------");
        System.out.println(new Date());
        //导入物流费用明细表和库内操作表
        ExcelUtil<DraggingCabinet> operationsUtil = new ExcelUtil<DraggingCabinet>(DraggingCabinet.class);
        ExcelUtil<Invoice> detailsUtil = new ExcelUtil<Invoice>(Invoice.class);
        List<DraggingCabinet> operationsList = new ArrayList<>();
        List<Invoice> detailsList = new ArrayList<>();
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null && costFile.getOriginalFilename().contains("拖柜账单")) {
            operationsList = operationsUtil.importExcel(costFile.getInputStream());
        }
        System.out.println("拖柜账单");
        if (detailsFile != null) {
            // 导入第二个Excel文件明细
            if (detailsFile.getOriginalFilename() != null && detailsFile.getOriginalFilename().contains("拖柜发票")) {
                detailsList = detailsUtil.importExcel(detailsFile.getInputStream());
            }
        }
        System.out.println("拖柜数据导入完成");
        List<Invoice> invoiceList = detailsList;
        operationsList.parallelStream().forEach(item -> {
            draggingCabinetCost(item);
            if ((item.getWareHouse().contains("美西1号") && item.getName().contains("德泰客")) || (item.getWareHouse().contains("sav") && item.getName().contains("效合")) ||
                    (item.getWareHouse().contains("美西1号") && item.getName().contains("效合")) || (item.getWareHouse().contains("NJ") && item.getName().contains("效合")) ||
                    (item.getWareHouse().contains("美西2号仓") && item.getName().contains("效合")) || (item.getWareHouse().contains("美西仓") && item.getName().contains("效合"))
                    || (item.getWareHouse().contains("CANEW仓") && item.getName().contains("效合"))) {


                if ((item.getWareHouse().contains("sav") && item.getName().contains("效合")) || (item.getWareHouse().contains("NJ") && item.getName().contains("效合")) ||
                        (item.getWareHouse().contains("美西仓") && item.getName().contains("效合")) || (item.getWareHouse().contains("CANEW仓") && item.getName().contains("效合"))) {
                    if (item.getWeight().compareTo(new BigDecimal(48000.00)) >= 0 && item.getWeight().compareTo(new BigDecimal(52000.00)) < 0) {
                        item.setOverweightFeeCustomer(new BigDecimal(250));
                        item.setInvoice(item.getInvoice().add(item.getOverweightFeeCustomer()));
                    }
                }
                for (Invoice inv : invoiceList) {
                    if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                        if ((item.getWareHouse().contains("美西1号") && item.getName().contains("德泰客"))
                                || (item.getWareHouse().contains("美西1号") && item.getName().contains("效合"))
                                || (item.getWareHouse().contains("美西2号") && item.getName().contains("效合"))) {
                            if ((item.getWareHouse().contains("美西1号") && item.getName().contains("德泰客"))) {
                                //提货费
                                item.setPickUpChargeCustomer(new BigDecimal(900.00));
                                item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                            }
                            if ((item.getWareHouse().contains("美西1号") && item.getName().contains("效合"))) {
                                //提货费
                                item.setPickUpChargeCustomer(new BigDecimal(845.00));
                                item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                            }
                            if ((item.getWareHouse().contains("美西2号") && item.getName().contains("效合"))) {
                                //提货费
                                item.setPickUpChargeCustomer(new BigDecimal(795.00));
                                item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                            }
                            item.setProfit(inv.getInvoiceAll());
                        } else {
                            item.setPickUpChargeCustomer(inv.getPickUpChargeInvoice());
                            item.setPierPassFeeCustomer(inv.getPierPassFeeInvoice());
                            item.setChassisFeeCustomer(inv.getChassisFeeInvoiceMoney());
                            item.setCleaningFeeCustomer(inv.getCleaningFeeInvoice());
                            item.setDemurrageChargesCustomer(inv.getDemurrageChargesInvoice());
                            item.setPerDiemFreeCustomer(inv.getPerDiemFreeInvoice());
                            item.setPrePullFeeCustomer(inv.getPrePullFeeInvoice());
                            item.setYardStorageFeeCustomer(inv.getYardStorageFeeInvoice());
                            item.setDropLoadFeeCustomer(inv.getDropLoadFeeInvoice());
                            item.setWaitFreeCustomer(inv.getWaitFreeInvoice());
                            item.setChassisSeparationFeeCustomer(inv.getChassisSeparationFeeInvoice());
                            item.setEmergencyChargesFeeCustomer(inv.getEmergencyChargesFeeInvoice());
                            item.setOtherFeeCustomer(inv.getOtherFeeInvoice());
                            item.setProfit(inv.getInvoiceAll());
                            item.setInvoice(item.getInvoice().
                                    add(item.getPickUpChargeCustomer()).
                                    add(item.getPierPassFeeCustomer()).
                                    add(item.getChassisFeeCustomer()).
                                    add(item.getCleaningFeeCustomer()).
                                    add(item.getDemurrageChargesCustomer()).
                                    add(item.getPerDiemFreeCustomer()).
                                    add(item.getPrePullFeeCustomer()).
                                    add(item.getYardStorageFeeCustomer()).
                                    add(item.getDropLoadFeeCustomer()).
                                    add(item.getWaitFreeCustomer()).
                                    add(item.getChassisSeparationFeeCustomer()).
                                    add(item.getEmergencyChargesFeeCustomer()).
                                    add(item.getOtherFeeCustomer()));
                            break;
                        }
                    }
                }
            } else {
                if (item.getWareHouse().contains("CANEW") && !item.getName().contains("效合")) {
                    //提货费
                    item.setPickUpChargeCustomer(new BigDecimal(660.00));
                    item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                    //疏港费
                    if (item.getPierPassFee().compareTo(BigDecimal.ZERO) > 0) {
                        item.setPierPassFeeCustomer(new BigDecimal(75.00));
                        item.setInvoice(item.getInvoice().add(item.getPierPassFeeCustomer()));
                    }
                    //车架使用费
                    if (item.getChassisFee().compareTo(BigDecimal.ZERO) > 0) {
                        for (Invoice inv : invoiceList) {
                            if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                                item.setChassisFeeCustomer(inv.getChassisFeeInvoice().multiply(new BigDecimal(40)));
                                item.setInvoice(item.getInvoice().add(item.getChassisFeeCustomer()));
                                break;
                            }
                        }
                    }
                    //清洁费
                    if (item.getCleaningFee().compareTo(BigDecimal.ZERO) > 0) {
                        item.setCleaningFeeCustomer(new BigDecimal(25.00));
                        item.setInvoice(item.getInvoice().add(item.getCleaningFeeCustomer()));
                    }
                }
                if (item.getWareHouse().contains("美西2号") && !item.getName().contains("效合")) {
                    //提货费
                    item.setPickUpChargeCustomer(new BigDecimal(660.00));
                    item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                    //疏港费
                    if (item.getPierPassFee().compareTo(BigDecimal.ZERO) > 0) {
                        item.setPierPassFeeCustomer(new BigDecimal(75.00));
                        item.setInvoice(item.getInvoice().add(item.getPierPassFeeCustomer()));
                    }
                    //车架使用费
                    if (item.getChassisFee().compareTo(BigDecimal.ZERO) > 0) {
                        for (Invoice inv : invoiceList) {
                            if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                                item.setChassisFeeCustomer(inv.getChassisFeeInvoice().multiply(new BigDecimal(40)));
                                item.setInvoice(item.getInvoice().add(item.getChassisFeeCustomer()));
                                break;
                            }
                        }
                    }
                    //清洁费
                    if (item.getCleaningFee().compareTo(BigDecimal.ZERO) > 0) {
                        item.setCleaningFeeCustomer(new BigDecimal(25.00));
                        item.setInvoice(item.getInvoice().add(item.getCleaningFeeCustomer()));
                    }
                }
                if (item.getWareHouse().contains("美西1号") && !item.getName().contains("效合") && !item.getName().contains("德泰客")) {
                    //提货费
                    if (item.getPickUpCharge().compareTo(BigDecimal.ZERO) > 0) {
                        item.setPickUpChargeCustomer(new BigDecimal(700.00));
                        item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                    }
                    //疏港费
                    if (item.getPierPassFee().compareTo(BigDecimal.ZERO) > 0) {
                        item.setPierPassFeeCustomer(new BigDecimal(75.00));
                        item.setInvoice(item.getInvoice().add(item.getPierPassFeeCustomer()));
                    }
                    //车架使用费
                    if (item.getChassisFee().compareTo(BigDecimal.ZERO) > 0) {
                        for (Invoice inv : invoiceList) {
                            if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                                item.setChassisFeeCustomer(inv.getChassisFeeInvoice().multiply(new BigDecimal(40)));
                                item.setInvoice(item.getInvoice().add(item.getChassisFeeCustomer()));
                                break;
                            }
                        }
                    }
                    //清洁费
                    if (item.getCleaningFee().compareTo(BigDecimal.ZERO) > 0) {
                        item.setCleaningFeeCustomer(new BigDecimal(25.00));
                        item.setInvoice(item.getInvoice().add(item.getCleaningFeeCustomer()));
                    }
                }
                if (item.getWareHouse().contains("美西4号") && !item.getName().contains("效合")) {
                    //提货费
                    if (item.getPickUpCharge().compareTo(BigDecimal.ZERO) > 0) {
                        item.setPickUpChargeCustomer(new BigDecimal(700.00));
                        item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                    }
                    //疏港费
                    if (item.getPierPassFee().compareTo(BigDecimal.ZERO) > 0) {
                        item.setPierPassFeeCustomer(new BigDecimal(75.00));
                        item.setInvoice(item.getInvoice().add(item.getPierPassFeeCustomer()));
                    }
                    //车架使用费
                    if (item.getChassisFee().compareTo(BigDecimal.ZERO) > 0) {
                        for (Invoice inv : invoiceList) {
                            if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                                item.setChassisFeeCustomer(inv.getChassisFeeInvoice().multiply(new BigDecimal(40)));
                                item.setInvoice(item.getInvoice().add(item.getChassisFeeCustomer()));
                                break;
                            }
                        }
                    }
                    //清洁费
                    if (item.getCleaningFee().compareTo(BigDecimal.ZERO) > 0) {
                        item.setCleaningFeeCustomer(new BigDecimal(25.00));
                        item.setInvoice(item.getInvoice().add(item.getCleaningFeeCustomer()));
                    }
                }
                if (item.getWareHouse().contains("sav") && !item.getName().contains("效合")) {
                    //提货费
                    if (item.getPickUpCharge().compareTo(BigDecimal.ZERO) > 0) {
                        item.setPickUpChargeCustomer(new BigDecimal(350.00));
                        item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                    }
                    //车架使用费
                    if (item.getChassisFee().compareTo(BigDecimal.ZERO) > 0) {
                        for (Invoice inv : invoiceList) {
                            if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                                item.setChassisFeeCustomer(inv.getChassisFeeInvoice().multiply(new BigDecimal(45)));
                                item.setInvoice(item.getInvoice().add(item.getChassisFeeCustomer()));
                                break;
                            }
                        }
                    }
                }
                if (item.getWareHouse().contains("NJ") && !item.getName().contains("效合")) {
                    //提货费
                    if (item.getPickUpCharge().compareTo(BigDecimal.ZERO) > 0) {
                        item.setPickUpChargeCustomer(new BigDecimal(800.00));
                        item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
                    }
                    //车架使用费
                    if (item.getChassisFee().compareTo(BigDecimal.ZERO) > 0) {
                        for (Invoice inv : invoiceList) {
                            if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                                item.setChassisFeeCustomer(inv.getChassisFeeInvoice().multiply(new BigDecimal(40)));
                                item.setInvoice(item.getInvoice().add(item.getChassisFeeCustomer()));
                                break;
                            }
                        }
                    }
                }

                //滞期费
                if (item.getDemurrageCharges().compareTo(BigDecimal.ZERO) > 0) {
                    for (Invoice inv : invoiceList) {
                        if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                            item.setDemurrageChargesCustomer(inv.getDemurrageChargesInvoice());
                            item.setInvoice(item.getInvoice().add(item.getDemurrageChargesCustomer()));
                            break;
                        }
                    }
                }
                //箱使费
                if (item.getPerDiemFree().compareTo(BigDecimal.ZERO) > 0) {
                    for (Invoice inv : invoiceList) {
                        if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                            item.setPerDiemFreeCustomer(inv.getPerDiemFreeInvoice());
                            item.setInvoice(item.getInvoice().add(item.getPerDiemFreeCustomer()));
                            break;
                        }
                    }
                }
                //预提费
                if (item.getPrePullFee().compareTo(BigDecimal.ZERO) > 0) {
                    item.setPrePullFeeCustomer(new BigDecimal(150.00));
                    item.setInvoice(item.getInvoice().add(item.getPrePullFeeCustomer()));
                }
                //过夜费
                if (item.getYardStorageFee().compareTo(BigDecimal.ZERO) > 0) {
                    item.setYardStorageFeeCustomer(new BigDecimal(50.00));
                    item.setInvoice(item.getInvoice().add(item.getYardStorageFeeCustomer()));
                }
                //Drop Off drop load费
                if (item.getDropLoadFee().compareTo(BigDecimal.ZERO) > 0) {
                    item.setDropLoadFeeCustomer(new BigDecimal(150.00));
                    item.setInvoice(item.getInvoice().add(item.getDropLoadFeeCustomer()));
                }
                //等候费

                //底盘分离费
                if (item.getChassisSeparationFee().compareTo(BigDecimal.ZERO) > 0) {
                    for (Invoice inv : invoiceList) {
                        if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                            item.setChassisSeparationFeeCustomer(inv.getChassisSeparationFeeInvoice());
                            item.setInvoice(item.getInvoice().add(item.getChassisSeparationFeeCustomer()));
                            break;
                        }
                    }
                }
                //超重费
                if (item.getOverweightFee().compareTo(BigDecimal.ZERO) > 0) {
                    if (item.getWeight().compareTo(new BigDecimal(42000.00)) >= 0 && item.getWeight().compareTo(new BigDecimal(48000.00)) < 0) {
                        item.setOverweightFeeCustomer(new BigDecimal(250.00));
                    } else if (item.getWeight().compareTo(new BigDecimal(48000.00)) >= 0 && item.getWeight().compareTo(new BigDecimal(52000.00)) < 0) {
                        item.setOverweightFeeCustomer(new BigDecimal(300.00));
                    } else if (item.getWeight().compareTo(new BigDecimal(52000.00)) >= 0 && item.getWeight().compareTo(new BigDecimal(56000.00)) < 0) {
                        item.setOverweightFeeCustomer(new BigDecimal(350.00));
                    }
                    item.setInvoice(item.getInvoice().add(item.getOverweightFeeCustomer()));
                }
                //pdf金额
                for (Invoice inv : invoiceList) {
                    if (item.getCabinetNumber().equals(inv.getCabinetNumber())) {
                        //其他费用
                        item.setOtherFeeCustomer(inv.getOtherFeeInvoice());
                        item.setInvoice(item.getInvoice().add(item.getOtherFeeCustomer()));
                        //加急费
                        item.setEmergencyChargesFeeCustomer(inv.getEmergencyChargesFeeInvoice());
                        item.setInvoice(item.getInvoice().add(item.getEmergencyChargesFeeCustomer()));
                        item.setProfit(inv.getInvoiceAll());
                    }
                }
            }

            if (item.getPickUpCharge().compareTo(item.getPickUpChargeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/提货费");
            }
            if (item.getPierPassFee().compareTo(item.getPierPassFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/疏港费");
            }
            if (item.getChassisFee().compareTo(item.getChassisFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/车架使用费");
            }
            if (item.getCleaningFee().compareTo(item.getCleaningFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/清洁费");
            }
            if (item.getDemurrageCharges().compareTo(item.getDemurrageChargesCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/滞期费");
            }
            if (item.getPerDiemFree().compareTo(item.getPerDiemFreeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/箱使费");
            }
            if (item.getPrePullFee().compareTo(item.getPrePullFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/预提费");
            }
            if (item.getYardStorageFee().compareTo(item.getYardStorageFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/过夜费");
            }

            if (item.getDropLoadFee().compareTo(item.getDropLoadFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/drop load费");
            }
            if (item.getWaitFree().compareTo(item.getWaitFreeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/等候费");
            }
            if (item.getChassisSeparationFee().compareTo(item.getChassisSeparationFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/底盘分离费");
            }
            if (item.getOverweightFee().compareTo(item.getOverweightFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/超重费");
            }
            if (item.getEmergencyChargesFee().compareTo(item.getEmergencyChargesFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/加急费");
            }
            if (item.getOtherFee().compareTo(item.getOtherFeeCustomer()) != 0) {
                item.setRemarks(item.getRemarks() + "/其他费用");
            }
            item.setMargin(item.getTotal().subtract(item.getProfit()));
            if (item.getName().contains("效合")) {
                if (item.getMargin().compareTo(BigDecimal.ZERO) != 0) {
                    item.setResult("错误");
                }
            } else if (item.getName().contains("德泰客") && item.getWareHouse().contains("美西")) {
                if (item.getMargin().compareTo(new BigDecimal(80.00)) > 0 || item.getMargin().compareTo(BigDecimal.ZERO) < 0) {
                    item.setResult("错误");
                }
            } else if (item.getWareHouse().contains("美西2号") || item.getWareHouse().contains("美西1号") || item.getWareHouse().contains("NJ")) {
                if (item.getMargin().compareTo(new BigDecimal(100.00)) != 0) {
                    item.setResult("错误");
                }
            } else if (item.getWareHouse().contains("美西4号")) {
                if (item.getMargin().compareTo(new BigDecimal(70.00)) != 0) {
                    item.setResult("错误");
                }
            } else if (item.getWareHouse().contains("sav")) {
                if (item.getMargin().compareTo(new BigDecimal(50.00)) <= 0) {
                    item.setResult("错误");
                }
            }


//            if (item.getName().contains("效合")) {
//                for(Invoice inv :invoiceList){
//                    if(item.getCabinetNumber().equals(inv.getCabinetNumber())){
//                        item.setPickUpChargeCustomer(inv.getPickUpChargeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getPickUpChargeCustomer()));
//                        //
//                        item.setPierPassFeeCustomer(inv.getPierPassFeeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getPierPassFeeCustomer()));
//                        //
//                        item.setChassisFeeCustomer(inv.getChassisFeeInvoice().multiply(new BigDecimal(40)));
//                        item.setInvoice(item.getInvoice().add(item.getChassisFeeCustomer()));
//                        //
//                        item.setCleaningFeeCustomer(inv.getCleaningFeeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getCleaningFeeCustomer()));
//                        //
//                        item.setDemurrageChargesCustomer(inv.getDemurrageChargesInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getDemurrageChargesCustomer()));
//                        //
//                        item.setPerDiemFreeCustomer(inv.getPerDiemFreeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getPerDiemFreeCustomer()));
//                        //1111111
//                        //
//                        item.setPrePullFeeCustomer(inv.getPrePullFeeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getPrePullFeeCustomer()));
//                        //
//                        item.setYardStorageFeeCustomer(inv.getYardStorageFeeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getYardStorageFeeCustomer()));
//                        //
//                        item.setDropLoadFeeCustomer(inv.getDropLoadFeeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getDropLoadFeeCustomer()));
//                        //
//                        item.setWaitFreeCustomer(inv.getWaitFreeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getWaitFreeCustomer()));
//                        //
//                        item.setChassisSeparationFeeCustomer(inv.getChassisSeparationFeeInvoice());
//                        item.setInvoice(item.getInvoice().add(item.getChassisSeparationFeeCustomer()));
//
//                    }
//                }
//                if (item.getWeight().compareTo(new BigDecimal(44000.00)) >= 0 && item.getWeight().compareTo(new BigDecimal(48000.00)) < 0) {
//                    item.setOverweightFeeCustomer(new BigDecimal(250.00));
//                    item.setInvoice(item.getInvoice().add(item.getOverweightFeeCustomer()));
//                }
//            }

            //加急费

            //其他费用

        });
        ExcelUtil<DraggingCabinet> util = new ExcelUtil<DraggingCabinet>(DraggingCabinet.class);
        util.exportExcel(response, operationsList, "成本模板");
        System.out.println("6666666666666666666666666666666666666666666666666666666");
    }

    @Override
    public void draggingCabinetExportTemplate(HttpServletResponse response) {
        ExcelUtil<DraggingCabinet> util = new ExcelUtil<DraggingCabinet>(DraggingCabinet.class);
        util.exportExcel(response, null, "拖柜账单");
    }

    // 自定义方法获取标题
    private List<List<String>> getHead() {
        // 定义标题和对应的字段名称
        String[][] titlesAndFields = {
                {"出库仓库", "wareHouse"},
                {"订单编号", "orderNo"},
                {"销售平台", "salesPlatform"},
                {"提审时间", "submissionTime"},
                {"处理时间", "processingTime"},
                {"发货时间", "deliveryTime"},
                {"收货人", "consignee"},
                {"国家", "country"},
                {"州/省", "province"},
                {"城市", "city"},
                {"邮编", "postalCode"},
                {"分区", "partition"},
                {"包裹单位", "unit"},
                {"包裹长(CM)", "length"},
                {"包裹宽(CM)", "width"},
                {"包裹高(CM)", "height"},
                {"包裹重量(g)", "weight"},
                {"计费重(LB)", "billingWeight"},
                {"SKU数量", "SKUNum"},
                {"SKU1", "SKU1"},
                {"SKU1数量", "SKU1Num"},
                {"SKU2", "SKU2"},
                {"SKU2数量", "SKU2Num"},
                {"SKU3", "SKU3"},
                {"SKU3数量", "SKU3Num"},
                {"SKU4", "SKU4"},
                {"SKU4数量", "SKU4Num"},
                {"SKU5", "SKU5"},
                {"SKU5数量", "SKU5Num"},
                {"物流商", "logisticsProvider"},
                {"物流方式", "logisticsMethod"},
                {"自有运单", "waybill"},
                {"运单号", "waybillNum"},
                {"基础运费", "Basic Rate"},
                {"操作附加费-超尺寸", "AHS - Dimensions"},
                {"操作附加费-超重", "AHS - Weight"},
                {"旺季额外附加费", "Demand - AHS Charge"},
                {"超大超尺寸", "Oversize Charge"},
                {"旺季超大超尺寸附加费", "Demand - Oversize Surcharge"},
                {"住宅附加费", "Residential Surcharge"},
                {"住宅旺季附加费", "Demand  - Residential Delivery Charge"},
                {"包裹旺季附加费", "Demand Surcharge"},
                {"偏远地区附加费1", "DAS Resi"},
                {"偏远地区附加费2", "DAS - Ground (Comm)"},
                {"偏远地区附加费3", "Delivery Area Surcharge"},
                {"超偏远地区附加费1", "DAS EXTENDED - Home Delivery (Resi)"},
                {"超偏远地区附加费2", "DAS EXTENDED - Ground (Comm)"},
                {"超偏远地区附加费3", "delivery Area Surcharge Extended"},
                {"超级偏远地区附加费1", "DAS Remote Comm(Ground)"},
                {"超级偏远地区附加费2", "DAS Remote Resi (Home Delivery)"},
                {"超级偏远地区附加费3", "Delivery Area Surcharge Remote Residential"},
                {"签名服务费", "Indirect signature required"},
                {"燃油附加费", "Fuel Surcharge"},
                {"操作费", "operationFee"},
                {"自有运单计费", "waybillCost"},
                {"Label费", "LabelCost"},
                {"费用合计", "totalCost"},
                {"客户编码", "customerNode"},
                {"客户名称", "customerName"},
                {"客户昵称", "customerNickname"},
        };

// 使用流来创建标题列表
        List<List<String>> headList = Arrays.stream(titlesAndFields)
                .map(Arrays::asList)
                .collect(Collectors.toList());

        return headList;
    }

    private List<List<String>> getHeadCost() {
        // 定义标题和对应的字段名称
        String[][] titlesAndFields = {
                {"出库仓库", "wareHouse"},
                {"订单编号", "orderNo"},
                {"销售平台", "salesPlatform"},
                {"提审时间", "submissionTime"},
                {"处理时间", "processingTime"},
                {"发货时间", "deliveryTime"},
                {"收货人", "consignee"},
                {"国家", "country"},
                {"州/省", "province"},
                {"城市", "city"},
                {"邮编", "postalCode"},
                {"分区", "partition"},
                {"包裹长(CM)", "length"},
                {"包裹宽(CM)", "width"},
                {"包裹高(CM)", "height"},
                {"包裹重量(g)", "weight"},
                {"计费重(LB)", "billingWeight"},
                {"SKU数量", "SKUNum"},
                {"SKU1", "SKU1"},
                {"SKU1数量", "SKU1Num"},
                {"SKU2", "SKU2"},
                {"SKU2数量", "SKU2Num"},
                {"SKU3", "SKU3"},
                {"SKU3数量", "SKU3Num"},
                {"SKU4", "SKU4"},
                {"SKU4数量", "SKU4Num"},
                {"SKU5", "SKU5"},
                {"SKU5数量", "SKU5Num"},
                {"物流商", "logisticsProvider"},
                {"物流方式", "logisticsMethod"},
                {"自有运单", "waybill"},
                {"运单号", "waybillNum"},
                {"基础运费", "Basic Rate"},
                {"操作附加费-超尺寸", "AHS - Dimensions"},
                {"操作附加费-超重", "AHS - Weight"},
                {"旺季额外附加费", "Demand - AHS Charge"},
                {"超大超尺寸", "Oversize Charge"},
                {"旺季超大超尺寸附加费", "Demand - Oversize Surcharge"},
                {"住宅附加费", "Residential Surcharge"},
                {"住宅旺季附加费", "Demand  - Residential Delivery Charge"},
                {"包裹旺季附加费", "Demand Surcharge"},
                {"偏远地区附加费1", "DAS Resi"},
                {"偏远地区附加费2", "DAS - Ground (Comm)"},
                {"偏远地区附加费3", "Delivery Area Surcharge"},
                {"超偏远地区附加费1", "DAS EXTENDED - Home Delivery (Resi)"},
                {"超偏远地区附加费2", "DAS EXTENDED - Ground (Comm)"},
                {"超偏远地区附加费3", "delivery Area Surcharge Extended"},
                {"超级偏远地区附加费1", "DAS Remote Comm(Ground)"},
                {"超级偏远地区附加费2", "DAS Remote Resi (Home Delivery)"},
                {"超级偏远地区附加费3", "Delivery Area Surcharge Remote Residential"},
                {"签名服务费", "Indirect signature required"},
                {"燃油附加费", "Fuel Surcharge"},
                {"费用合计", "totalCost"},
                {"客户编码", "customerNode"},
                {"基础运费成本", "Basic Rate Cost"},
                {"操作附加费-超尺寸成本", "AHS - Dimensions Cost"},
                {"操作附加费-超重成本", "AHS - Weight Cost"},
                {"旺季额外附加费成本", "Demand - AHS Charge Cost"},
                {"超大超尺寸成本", "Oversize Charge Cost"},
                {"旺季超大超尺寸附加费成本", "Demand - Oversize Surcharge Cost"},
                {"住宅附加费成本", "Residential Surcharge Cost"},
                {"住宅旺季附加费成本", "Demand  - Residential Delivery Charge Cost"},
                {"包裹旺季附加费成本", "Demand Surcharge Cost"},
                {"偏远地区附加费1成本", "DAS Resi Cost"},
                {"偏远地区附加费2成本", "DAS - Ground (Comm) Cost"},
                {"偏远地区附加费3成本", "Delivery Area Surcharge Cost"},
                {"ECONOMY偏远成本", "DAS"},
                {"超偏远地区附加费1成本", "DAS EXTENDED - Home Delivery (Resi) Cost"},
                {"超偏远地区附加费2成本", "DAS EXTENDED - Ground (Comm) Cost"},
                {"超偏远地区附加费3成本", "delivery Area Surcharge Extended Cost"},
                {"ECONOMY超偏远成本", "DASExtended"},
                {"超级偏远地区附加费1成本", "DAS Remote Comm(Ground) Cost"},
                {"超级偏远地区附加费2成本", "DAS Remote Resi (Home Delivery) Cost"},
                {"超级偏远地区附加费3成本", "Delivery Area Surcharge Remote Residential Cost"},
                {"签名服务费成本", "Indirect signature required Cost"},
                {"燃油附加费成本", "Fuel Surcharge Cost"},
                {"成本合计", "AmountCost"},
                {"销售利润率", "SalesProfit"},
                {"备注", "column"},
        };

// 使用流来创建标题列表
        List<List<String>> headList = Arrays.stream(titlesAndFields)
                .map(Arrays::asList)
                .collect(Collectors.toList());
        return headList;
    }

    private List<List<String>> getHeadLongCost() {
        // 定义标题和对应的字段名称
        String[][] titlesAndFields = {


                {"运单号", "运单号"},
                {"Actual Weight Amount", "实际重量"},
                {"Estimated Weight", "估计重量"},
                {"Rated Weight Amount", "额定重量"},
                {"Dim Length", "长"},
                {"Dim Width", "宽"},
                {"Dim Height", "高"},
                {"物流方式", "物流方式"},
                //{"Rated Weight Amount", "计费重(LB)"},
                {"Recipient Zip Code", "邮编"},
                {"Zone Code", "分区"},
                {"Net Charge Amount", "总费用"},
                {"base rate", "基础运费"},
                {"Fuel Surcharge", "燃油附加费"},
                {"Demand-Add'l Handling", "旺季额外附加费"},
                {"Demand-Oversize", "旺季超大超尺寸附加费"},
                {"Demand Surcharge", "包裹旺季附加费"},
                {"Oversize Charge", "超大超尺寸"},
                {"AHS - Dimensions", "操作附加费-超尺寸"},
                {"AHS - Weight", "操作附加费-超重"},
                {"Additional Handling", "操作附加费-包装"},
                {"Residential", "住宅附加费"},
                {"DAS Resi", "偏远地区附加费1"},
                {"DAS Comm", "偏远地区附加费2"},
                {"DAS Extended Resi", "超偏远地区附加费1"},
                {"DAS Extended Comm", "超偏远地区附加费2"},
                {"DAS Remote Residential", "超级偏远地区附加费3"},
                {"DAS Remote Comm", "超级偏远地区附加费1"},
                {"Address Correction", "地址更正费"},
                {"Delivery Area Surcharge", "Delivery Area Surcharge"},
                {"Delivery Area Surcharge Extended", "Delivery Area Surcharge Extended"},
                {"Earned Discount", "Earned Discount"},
                {"Grace Discount", "Grace Discount"},
                {"Performance Pricing", "Performance Pricing"},
                {"Transportation Charge Amount", "Transportation Charge Amount"},
                //----------------------------------
                {"base rate cost", "基础运费成本"},
                {"Fuel Surcharge Cost", "燃油附加费成本"},
                {"Demand-Add'l Handling Cost", "旺季额外附加费成本"},
                {"Demand-Oversize Cost", "旺季超大超尺寸附加费成本"},
                {"Demand Surcharge Cost", "包裹旺季附加费成本"},
                {"Oversize Charge Cost", "超大超尺寸成本"},
                {"AHS - Dimensions Cost", "操作附加费-超尺寸成本"},
                {"AHS - Weight Cost", "操作附加费-超重成本"},
                {"Additional Handling Cost", "操作附加费-包装成本"},
                {"Residential Cost", "住宅附加费成本"},
                {"Demand Residential Cost", "住宅附加费成本-旺季"},
                {"DAS Resi Cost", "偏远地区附加费1成本"},
                {"DAS Comm Cost", "偏远地区附加费2成本"},
                {"DAS Extended Resi Cost", "超偏远地区附加费1成本"},
                {"DAS Extended Comm Cost", "超偏远地区附加费2成本"},
                {"DAS Remote Residential Cost", "超级偏远地区附加费3成本"},
                {"DAS Remote Comm Cost", "超级偏远地区附加费1成本"},
                {"Address Correction Cost", "地址更正费成本"},
                {"Amount", "核对金额（合计）"},
                {"Difference", "差异"},
                {"Text", "提报"},

        };

// 使用流来创建标题列表
        List<List<String>> headList = Arrays.stream(titlesAndFields)
                .map(Arrays::asList)
                .collect(Collectors.toList());
        return headList;
    }

    private List<List<String>> getHeadSurroundCost() {
        // 定义标题和对应的字段名称
        String[][] titlesAndFields = {
                {"长(CM)"},
                {"宽(CM)"},
                {"高(CM)"},
                {"围长(inch)"},
                {"实重(lb)"},
                {"计费重"},
                {"邮编"},
                {"分区"},
                {"是否偏远"},
                {"是否为AHS或OVERSIZE"},
                {"基础运费"},
                {"燃油附加费"},
                {"旺季额外附加费"},
                {"旺季超大超尺寸附加费"},
                {"包裹旺季附加费"},
                {"超大超尺寸"},
                {"操作附加费-超尺寸"},
                {"操作附加费-超重"},
                {"住宅附加费"},
                {"旺季住宅附加费"},
                {"偏远地区附加费1"},
                {"偏远地区附加费2"},
                {"超偏远地区附加费1"},
                {"超偏远地区附加费2"},
                {"超级偏远地区附加费3"},
                {"超级偏远地区附加费1"},
                {"合计"},
//                //----------------------------------
//                {"base rate cost", "基础运费成本"},
//                {"Fuel Surcharge Cost", "燃油附加费成本"},
//                {"Demand-Add'l Handling Cost", "旺季额外附加费成本"},
//                {"Demand-Oversize Cost", "旺季超大超尺寸附加费成本"},
//                {"Demand Surcharge Cost", "包裹旺季附加费成本"},
//                {"Oversize Charge Cost", "超大超尺寸成本"},
//                {"AHS - Dimensions Cost", "操作附加费-超尺寸成本"},
//                {"AHS - Weight Cost", "操作附加费-超重成本"},
//                {"Additional Handling Cost", "操作附加费-超尺寸成本"},
//                {"Residential Cost", "住宅附加费成本"},
//                {"DAS Resi Cost", "偏远地区附加费1成本"},
//                {"DAS Comm Cost", "偏远地区附加费2成本"},
//                {"DAS Extended Resi Cost", "超偏远地区附加费1成本"},
//                {"DAS Extended Comm Cost", "超偏远地区附加费2成本"},
//                {"DAS Remote Residential Cost", "超级偏远地区附加费3成本"},
//                {"DAS Remote Comm Cost", "超级偏远地区附加费1成本"},
//                {"Address Correction Cost", "地址更正费成本"},
//                {"Amount", "核对金额（合计）"},
//                {"Difference", "差异"},
//                {"Text", "提报"},

        };

// 使用流来创建标题列表
        List<List<String>> headList = Arrays.stream(titlesAndFields)
                .map(Arrays::asList)
                .collect(Collectors.toList());
        return headList;
    }

    private List<List<String>> getCustomerCost() {
        // 定义标题和对应的字段名称
        String[][] titlesAndFields = {
                {"出库仓库", "wareHouse"},
                {"订单编号", "orderNo"},
                {"销售平台", "salesPlatform"},
                {"提审时间", "submissionTime"},
                {"处理时间", "processingTime"},
                {"发货时间", "deliveryTime"},
                {"收货人", "consignee"},
                {"国家", "country"},
                {"州/省", "province"},
                {"城市", "city"},
                {"邮编", "postalCode"},
                {"分区", "partition"},
                {"单位", "unit"},
                {"包裹长(CM)", "length"},
                {"包裹宽(CM)", "width"},
                {"包裹高(CM)", "height"},
                {"包裹重量(g)", "weight"},
                {"计费重(LB)", "billingWeight"},
                {"SKU数量", "SKUNum"},
                {"SKU1", "SKU1"},
                {"SKU1数量", "SKU1Num"},
                {"SKU2", "SKU2"},
                {"SKU2数量", "SKU2Num"},
                {"SKU3", "SKU3"},
                {"SKU3数量", "SKU3Num"},
                {"SKU4", "SKU4"},
                {"SKU4数量", "SKU4Num"},
                {"SKU5", "SKU5"},
                {"SKU5数量", "SKU5Num"},
                {"物流商", "logisticsProvider"},
                {"物流方式", "logisticsMethod"},
                {"自有运单", "waybill"},
                {"运单号", "waybillNum"},
                {"基础运费", "Basic Rate"},
                {"操作附加费-超尺寸", "AHS - Dimensions"},
                {"操作附加费-超重", "AHS - Weight"},
                {"旺季额外附加费", "Demand - AHS Charge"},
                {"超大超尺寸", "Oversize Charge"},
                {"旺季超大超尺寸附加费", "Demand - Oversize Surcharge"},
                {"住宅附加费", "Residential Surcharge"},
                {"住宅旺季附加费", "Demand  - Residential Delivery Charge"},
                {"包裹旺季附加费", "Demand Surcharge"},
                {"偏远地区附加费1", "DAS Resi"},
                {"偏远地区附加费2", "DAS - Ground (Comm)"},
                {"偏远地区附加费3", "Delivery Area Surcharge"},
                {"超偏远地区附加费1", "DAS EXTENDED - Home Delivery (Resi)"},
                {"超偏远地区附加费2", "DAS EXTENDED - Ground (Comm)"},
                {"超偏远地区附加费3", "delivery Area Surcharge Extended"},
                {"超级偏远地区附加费1", "DAS Remote Comm(Ground)"},
                {"超级偏远地区附加费2", "DAS Remote Resi (Home Delivery)"},
                {"超级偏远地区附加费3", "Delivery Area Surcharge Remote Residential"},
                {"签名服务费", "Indirect signature required"},
                {"燃油附加费", "Fuel Surcharge"},
                {"费用合计", "totalCost"},
                {"客户编码", "customerNode"},
                {"基础运费成本", "Basic Rate Cost"},
                {"操作附加费-超尺寸成本", "AHS - Dimensions Cost"},
                {"操作附加费-超重成本", "AHS - Weight Cost"},
                {"旺季额外附加费成本", "Demand - AHS Charge Cost"},
                {"超大超尺寸成本", "Oversize Charge Cost"},
                {"旺季超大超尺寸附加费成本", "Demand - Oversize Surcharge Cost"},
                {"住宅附加费成本", "Residential Surcharge Cost"},
                {"住宅旺季附加费成本", "Demand  - Residential Delivery Charge Cost"},
                {"包裹旺季附加费成本", "Demand Surcharge Cost"},
                {"偏远地区附加费1成本", "DAS Resi Cost"},
                {"偏远地区附加费2成本", "DAS - Ground (Comm) Cost"},
                {"偏远地区附加费3成本", "Delivery Area Surcharge Cost"},
                {"超偏远地区附加费1成本", "DAS EXTENDED - Home Delivery (Resi) Cost"},
                {"超偏远地区附加费2成本", "DAS EXTENDED - Ground (Comm) Cost"},
                {"超偏远地区附加费3成本", "delivery Area Surcharge Extended Cost"},
                {"超级偏远地区附加费1成本", "DAS Remote Comm(Ground) Cost"},
                {"超级偏远地区附加费2成本", "DAS Remote Resi (Home Delivery) Cost"},
                {"超级偏远地区附加费3成本", "Delivery Area Surcharge Remote Residential Cost"},
                {"签名服务费成本", "Indirect signature required Cost"},
                {"燃油附加费成本", "Fuel Surcharge Cost"},
                {"合计", "AmountCost"},
        };

// 使用流来创建标题列表
        List<List<String>> headList = Arrays.stream(titlesAndFields)
                .map(Arrays::asList)
                .collect(Collectors.toList());
        return headList;
    }

    /**
     * 成本费用的
     *
     * @param item
     */
    private void zeroCost(LibraryOperationsCost item) {
        item.setBasicRateCost(new BigDecimal("0.00"));
        item.setAHSDimensionsCost(new BigDecimal("0.00"));
        item.setAHSWeightCost(new BigDecimal("0.00"));
        item.setDemandAHSChargeCost(new BigDecimal("0.00"));
        item.setOversizeChargeCost(new BigDecimal("0.00"));
        item.setDemandOversizeSurchargeCost(new BigDecimal("0.00"));
        item.setResidentialSurchargeCost(new BigDecimal("0.00"));
        item.setDemandResidentialDeliveryChargeCost(new BigDecimal("0.00"));
        item.setDemandSurchargeCost(new BigDecimal("0.00"));
        item.setDASResiCost(new BigDecimal("0.00"));
        item.setDASGroundCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeCost(new BigDecimal("0.00"));
        item.setDAS(new BigDecimal("0.00"));
        item.setDASEXTENDEDHomeDeliveryCost(new BigDecimal("0.00"));
        item.setDASEXTENDEDGroundCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal("0.00"));
        item.setDASExtended(new BigDecimal("0.00"));
        item.setDASRemoteCommCost(new BigDecimal("0.00"));
        item.setDASRemoteResiCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeRemoteResidentialCost(new BigDecimal("0.00"));
        item.setIndirectSignatureRequiredCost(new BigDecimal("0.00"));
        item.setFuelSurchargeCost(new BigDecimal("0.00"));
        item.setAmountCost(new BigDecimal("0.00"));
        item.setSalesProfit(new BigDecimal("0.00"));

    }

    /**
     * 超长成本费用的
     *
     * @param item
     */
    private void zeroLongCost(LongCost item) {
        item.setBaseRateCost(new BigDecimal("0.00"));
        item.setFuelSurchargeCost(new BigDecimal("0.00"));
        item.setDemandAddlHandlingCost(new BigDecimal("0.00"));
        item.setDemandOversizeCost(new BigDecimal("0.00"));
        item.setDemandSurchargeCost(new BigDecimal("0.00"));
        item.setOversizeChargeCost(new BigDecimal("0.00"));
        item.setAHSDimensionsCost(new BigDecimal("0.00"));
        item.setAHSWeightCost(new BigDecimal("0.00"));
        item.setAdditionalHandlingCost(new BigDecimal("0.00"));
        item.setResidentialCost(new BigDecimal("0.00"));
        item.setDemandResidentialCost(new BigDecimal("0.00"));
        item.setDASResiCost(new BigDecimal("0.00"));
        item.setDASCommCost(new BigDecimal("0.00"));
        item.setDASExtendedResiCost(new BigDecimal("0.00"));
        item.setDASExtendedCommCost(new BigDecimal("0.00"));
        item.setDASRemoteResidentialCost(new BigDecimal("0.00"));
        item.setDASRemoteCommCost(new BigDecimal("0.00"));
        item.setAddressCorrectionCost(new BigDecimal("0.00"));
        item.setAmount(new BigDecimal("0.00"));
        item.setDifference(new BigDecimal("0.00"));


    }

    private void zeroSurroundCost(SurroundCost item) {
        item.setBaseRate(new BigDecimal("0.00"));
        item.setFuelSurcharge(new BigDecimal("0.00"));
        item.setDemandAddlHandling(new BigDecimal("0.00"));
        item.setDemandOversize(new BigDecimal("0.00"));
        item.setDemandSurcharge(new BigDecimal("0.00"));
        item.setOversizeCharge(new BigDecimal("0.00"));
        item.setAHSDimensions(new BigDecimal("0.00"));
        item.setAHSWeight(new BigDecimal("0.00"));
        item.setResidential(new BigDecimal("0.00"));
        item.setResidentialBusy(new BigDecimal("0.00"));
        item.setDASResi(new BigDecimal("0.00"));
        item.setDASComm(new BigDecimal("0.00"));
        item.setDASExtendedResi(new BigDecimal("0.00"));
        item.setDASExtendedComm(new BigDecimal("0.00"));
        item.setDASRemoteResidential(new BigDecimal("0.00"));
        item.setDASRemoteComm(new BigDecimal("0.00"));
        item.setAmount(new BigDecimal("0.00"));
    }

    /**
     * 成本费用的
     *
     * @param item
     */
    private void customerCost(CustomerCost item) {

        item.setBaseRateCost(new BigDecimal("0.00"));
        item.setAHSDimensionsCost(new BigDecimal("0.00"));
        item.setAHSWeightCost(new BigDecimal("0.00"));
        item.setDemandAHSChargeCost(new BigDecimal("0.00"));
        item.setOversizeChargeCost(new BigDecimal("0.00"));
        item.setDemandOversizeSurchargeCost(new BigDecimal("0.00"));
        item.setResidentialSurchargeCost(new BigDecimal("0.00"));
        item.setDemandResidentialDeliveryChargeCost(new BigDecimal("0.00"));
        item.setDemandSurchargeCost(new BigDecimal("0.00"));
        item.setDASResiCost(new BigDecimal("0.00"));
        item.setDASGroundCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeCost(new BigDecimal("0.00"));
        item.setDASEXTENDEDHomeDeliveryCost(new BigDecimal("0.00"));
        item.setDASEXTENDEDGroundCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal("0.00"));
        item.setDASRemoteCommCost(new BigDecimal("0.00"));
        item.setDASRemoteResiCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeRemoteResidentialCost(new BigDecimal("0.00"));
        item.setIndirectSignatureRequiredCost(new BigDecimal("0.00"));
        item.setFuelSurchargeCost(new BigDecimal("0.00"));
        item.setAmount(new BigDecimal("0.00"));

    }

    /**
     * 拖柜的
     *
     * @param item
     */
    private void draggingCabinetCost(DraggingCabinet item) {
        item.setPickUpChargeCustomer(new BigDecimal("0.00"));
        item.setPierPassFeeCustomer(new BigDecimal("0.00"));
        item.setChassisFeeCustomer(new BigDecimal("0.00"));
        item.setCleaningFeeCustomer(new BigDecimal("0.00"));
        item.setDemurrageChargesCustomer(new BigDecimal("0.00"));
        item.setPerDiemFreeCustomer(new BigDecimal("0.00"));
        item.setPrePullFeeCustomer(new BigDecimal("0.00"));
        item.setYardStorageFeeCustomer(new BigDecimal("0.00"));
        item.setDropLoadFeeCustomer(new BigDecimal("0.00"));
        item.setWaitFreeCustomer(new BigDecimal("0.00"));
        item.setChassisSeparationFeeCustomer(new BigDecimal("0.00"));
        item.setOverweightFeeCustomer(new BigDecimal("0.00"));
        item.setEmergencyChargesFeeCustomer(new BigDecimal("0.00"));
        item.setOtherFeeCustomer(new BigDecimal("0.00"));
        item.setInvoice(new BigDecimal("0.00"));
        item.setProfit(new BigDecimal("0.00"));
        item.setRemarks("");

    }

}
